added stuff

This commit is contained in:
Win 2024-09-23 18:44:04 +07:00
parent a655c789bc
commit 6cfa24f1e3
6 changed files with 2254 additions and 1708 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,16 @@
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map_animations/flutter_map_animations.dart';
import 'package:flutter_map_supercluster/flutter_map_supercluster.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);
@ -7,7 +19,47 @@ class MapScreen extends StatefulWidget {
State<MapScreen> createState() => _MapScreenState(); State<MapScreen> createState() => _MapScreenState();
} }
class _MapScreenState extends State<MapScreen> { class _MapScreenState extends State<MapScreen> with TickerProviderStateMixin {
late List _stations = [];
late final List<Marker> markers;
late final SuperclusterImmutableController _superclusterController;
late final AnimatedMapController _animatedMapController;
@override
void initState() {
super.initState();
_superclusterController = SuperclusterImmutableController();
_animatedMapController = AnimatedMapController(vsync: this);
markers = [];
for (var i = 0; i < _stations.length; i++) {
final latLng =
LatLng(double.parse(_stations[i][4]), double.parse(_stations[i][5]));
markers.add(
Marker(
anchorPos: AnchorPos.align(AnchorAlign.top),
rotateAlignment: AnchorAlign.top.rotationAlignment,
height: 30,
width: 30,
point: latLng,
builder: (ctx) => const Icon(Icons.pin_drop),
),
);
}
}
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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -25,6 +77,64 @@ 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(
mapController: _animatedMapController.mapController,
options: MapOptions(
// center: LatLng((maxLatLng.latitude + minLatLng.latitude) / 2,
// (maxLatLng.longitude + minLatLng.longitude) / 2),
zoom: 6,
maxZoom: 15,
),
nonRotatedChildren: [
Builder(
builder: (context) =>
Text(FlutterMapState.maybeOf(context)!.zoom.toString()),
)
],
children: <Widget>[
TileLayer(
urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: const ['a', 'b', 'c'],
),
SuperclusterLayer.immutable(
initialMarkers: markers,
indexBuilder: IndexBuilders.computeWithOriginalMarkers,
controller: _superclusterController,
moveMap: (center, zoom) => _animatedMapController.animateTo(
dest: center,
zoom: zoom,
),
calculateAggregatedClusterData: true,
clusterWidgetSize: const Size(40, 40),
anchor: AnchorPos.align(AnchorAlign.center),
popupOptions: PopupOptions(
selectedMarkerBuilder: (context, marker) => const Icon(
Icons.pin_drop,
color: Colors.red,
),
popupDisplayOptions: PopupDisplayOptions(
builder: (BuildContext context, Marker marker) => Container(
color: Colors.white,
child: Text(marker.point.toString()),
),
),
),
builder: (context, position, markerCount, extraClusterData) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.blue),
child: Center(
child: Text(
markerCount.toString(),
style: const TextStyle(color: Colors.white),
),
),
);
},
),
],
),
); );
} }
} }

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