added station data

This commit is contained in:
Win 2024-09-23 17:13:40 +07:00
parent f32faad118
commit a655c789bc
4 changed files with 1744 additions and 3 deletions

1681
assets/data/stations.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,8 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@ -8,6 +12,24 @@ class HomeScreen extends StatefulWidget {
}
class _HomeScreenState extends State<HomeScreen> {
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"];
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -25,6 +47,41 @@ class _HomeScreenState extends State<HomeScreen> {
),
floatingActionButton: FloatingActionButton(
onPressed: () => {print("deez")}, child: const Icon(Icons.add)),
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])
],
)),
));
},
)),
);
}
}

View File

@ -7,10 +7,12 @@ import Foundation
import dynamic_color
import flutter_localization
import path_provider_foundation
import shared_preferences_foundation
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FlutterLocalizationPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalizationPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
}

View File

@ -1,5 +1,5 @@
name: srt_app
description: "A new Flutter project."
description: "An open source alternative to SRT Timetable."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
@ -38,6 +38,7 @@ dependencies:
dynamic_color: ^1.7.0
flutter_localization: ^0.2.2
gestures: ^1.0.0
path_provider: ^2.1.4
dev_dependencies:
flutter_test:
@ -62,8 +63,8 @@ flutter:
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
assets:
- assets/data/stations.json
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see