Compare commits

..

3 Commits

Author SHA1 Message Date
Win c7a1f130cf finished map markers 2024-09-23 19:37:32 +07:00
Win ffa0c0ff34 more stuff 2024-09-23 19:20:07 +07:00
Win 6cfa24f1e3 added stuff 2024-09-23 18:44:04 +07:00
6 changed files with 2207 additions and 1707 deletions

View File

@ -15,24 +15,9 @@ migration:
- platform: root - platform: root
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: android
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: ios
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: linux - platform: linux
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730 base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: macos
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: web
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: windows
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
# User provided section # User provided section

1681
assets/data/schedule.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -12,21 +12,21 @@ class HomeScreen extends StatefulWidget {
} }
class _HomeScreenState extends State<HomeScreen> { class _HomeScreenState extends State<HomeScreen> {
List _stations = []; List _schedule = [];
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_getStations(); _getSchedule();
} }
Future<void> _getStations() async { Future<void> _getSchedule() async {
final String stationFile = final String scheduleFile =
await rootBundle.loadString("assets/data/stations.json"); await rootBundle.loadString("assets/data/schedule.json");
final data = await json.decode(stationFile); final data = await json.decode(scheduleFile);
setState(() { setState(() {
_stations = data["records"]; _schedule = data["records"];
}); });
} }
@ -50,7 +50,7 @@ class _HomeScreenState extends State<HomeScreen> {
body: Container( body: Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0), padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: ListView.builder( child: ListView.builder(
itemCount: _stations.length, itemCount: _schedule.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return Card( return Card(
elevation: 4.0, elevation: 4.0,
@ -64,19 +64,19 @@ class _HomeScreenState extends State<HomeScreen> {
TextSpan(text: "เลขขบวน"), TextSpan(text: "เลขขบวน"),
TextSpan(text: "\n"), TextSpan(text: "\n"),
TextSpan( TextSpan(
text: _stations[index][1], text: _schedule[index][1],
style: TextStyle( style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold)), fontSize: 20, fontWeight: FontWeight.bold)),
])), ])),
title: Text(_stations[index][2]), title: Text(_schedule[index][2]),
subtitle: RichText( subtitle: RichText(
text: TextSpan( text: TextSpan(
children: <TextSpan>[ children: <TextSpan>[
TextSpan(text: "Arrival: "), TextSpan(text: "Arrival: "),
TextSpan(text: _stations[index][8]), TextSpan(text: _schedule[index][8]),
TextSpan(text: "\n"), TextSpan(text: "\n"),
TextSpan(text: "Departure: "), TextSpan(text: "Departure: "),
TextSpan(text: _stations[index][9]) TextSpan(text: _schedule[index][9])
], ],
)), )),
)); ));

View File

@ -1,4 +1,15 @@
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
}
class MapScreen extends StatefulWidget { class MapScreen extends StatefulWidget {
const MapScreen({Key? key}) : super(key: key); const MapScreen({Key? key}) : super(key: key);
@ -8,6 +19,48 @@ class MapScreen extends StatefulWidget {
} }
class _MapScreenState extends State<MapScreen> { class _MapScreenState extends State<MapScreen> {
List _stations = [];
List<Marker> _markers = [];
@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"];
_getMarkers();
});
}
Future<void> _getMarkers() async {
List<Marker> markers = [];
for (var i = 0; i < _stations.length; i++) {
markers.add(
Marker(
height: 30,
width: 30,
point: LatLng(double.tryParse(_stations[i][4].toString()) ?? 0,
double.tryParse(_stations[i][5].toString()) ?? 0),
builder: (ctx) =>
const Icon(Icons.pin_drop, color: Colors.brown, size: 50.0),
),
);
}
setState(() {
_markers = markers;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -25,6 +78,17 @@ class _MapScreenState extends State<MapScreen> {
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () => {print("deez")}, child: const Icon(Icons.add)), onPressed: () => {print("deez")}, child: const Icon(Icons.add)),
body: FlutterMap(
options:
MapOptions(center: const LatLng(13.736717, 100.523186), zoom: 10.0),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
//userAgentPackageName: 'net.winscloud.srt',
),
MarkerLayer(markers: _markers)
],
),
); );
} }
} }

View File

@ -39,6 +39,10 @@ dependencies:
flutter_localization: ^0.2.2 flutter_localization: ^0.2.2
gestures: ^1.0.0 gestures: ^1.0.0
path_provider: ^2.1.4 path_provider: ^2.1.4
flutter_map: any
latlong2: any
flutter_map_supercluster: any
flutter_map_animations: any
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
@ -64,6 +68,7 @@ flutter:
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
assets: assets:
- assets/data/schedule.json
- assets/data/stations.json - assets/data/stations.json
# - images/a_dot_ham.jpeg # - images/a_dot_ham.jpeg