srt_app/lib/pages/home.dart

88 lines
2.8 KiB
Dart
Raw Normal View History

2024-09-23 17:13:40 +07:00
import 'dart:convert';
2024-09-23 11:52:20 +07:00
import 'package:flutter/material.dart';
2024-09-23 17:13:40 +07:00
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
2024-09-23 11:52:20 +07:00
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
2024-09-23 18:44:04 +07:00
List _schedule = [];
2024-09-23 17:13:40 +07:00
@override
void initState() {
super.initState();
2024-09-23 18:44:04 +07:00
_getSchedule();
2024-09-23 17:13:40 +07:00
}
2024-09-23 18:44:04 +07:00
Future<void> _getSchedule() async {
final String scheduleFile =
await rootBundle.loadString("assets/data/schedule.json");
final data = await json.decode(scheduleFile);
2024-09-23 17:13:40 +07:00
setState(() {
2024-09-23 18:44:04 +07:00
_schedule = data["records"];
2024-09-23 17:13:40 +07:00
});
}
2024-09-23 11:52:20 +07:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Home'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('More')));
},
)
],
),
floatingActionButton: FloatingActionButton(
onPressed: () => {print("deez")}, child: const Icon(Icons.add)),
2024-09-23 17:13:40 +07:00
body: Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: ListView.builder(
2024-09-23 18:44:04 +07:00
itemCount: _schedule.length,
2024-09-23 17:13:40 +07:00
itemBuilder: (context, index) {
return Card(
elevation: 4.0,
margin: const EdgeInsets.symmetric(vertical: 5.0),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 25.0),
leading: RichText(
textAlign: TextAlign.center,
text: TextSpan(children: <TextSpan>[
TextSpan(text: "เลขขบวน"),
TextSpan(text: "\n"),
TextSpan(
2024-09-23 18:44:04 +07:00
text: _schedule[index][1],
2024-09-23 17:13:40 +07:00
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold)),
])),
2024-09-23 18:44:04 +07:00
title: Text(_schedule[index][2]),
2024-09-23 17:13:40 +07:00
subtitle: RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(text: "Arrival: "),
2024-09-23 18:44:04 +07:00
TextSpan(text: _schedule[index][8]),
2024-09-23 17:13:40 +07:00
TextSpan(text: "\n"),
TextSpan(text: "Departure: "),
2024-09-23 18:44:04 +07:00
TextSpan(text: _schedule[index][9])
2024-09-23 17:13:40 +07:00
],
)),
));
},
)),
2024-09-23 11:52:20 +07:00
);
}
}