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 17:13:40 +07:00
|
|
|
List _stations = [];
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_getStations();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _getStations() async {
|
|
|
|
final String stationFile =
|
|
|
|
await rootBundle.loadString("assets/data/stations.json");
|
|
|
|
final data = await json.decode(stationFile);
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_stations = data["records"];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
itemCount: _stations.length,
|
|
|
|
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(
|
|
|
|
text: _stations[index][1],
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20, fontWeight: FontWeight.bold)),
|
|
|
|
])),
|
|
|
|
title: Text(_stations[index][2]),
|
|
|
|
subtitle: RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
children: <TextSpan>[
|
|
|
|
TextSpan(text: "Arrival: "),
|
|
|
|
TextSpan(text: _stations[index][8]),
|
|
|
|
TextSpan(text: "\n"),
|
|
|
|
TextSpan(text: "Departure: "),
|
|
|
|
TextSpan(text: _stations[index][9])
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
},
|
|
|
|
)),
|
2024-09-23 11:52:20 +07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|