2024-09-23 18:44:04 +07:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2024-09-23 11:52:20 +07:00
|
|
|
import 'package:flutter/material.dart';
|
2024-09-23 18:44:04 +07:00
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
2024-09-23 19:20:07 +07:00
|
|
|
import 'package:flutter_map/flutter_map.dart';
|
2024-09-23 19:37:32 +07:00
|
|
|
|
2024-09-23 18:44:04 +07:00
|
|
|
import 'package:latlong2/latlong.dart';
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
}
|
2024-09-23 11:52:20 +07:00
|
|
|
|
|
|
|
class MapScreen extends StatefulWidget {
|
|
|
|
const MapScreen({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<MapScreen> createState() => _MapScreenState();
|
|
|
|
}
|
|
|
|
|
2024-09-23 19:20:07 +07:00
|
|
|
class _MapScreenState extends State<MapScreen> {
|
|
|
|
List _stations = [];
|
|
|
|
List<Marker> _markers = [];
|
2024-09-23 18:44:04 +07:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
2024-09-23 19:20:07 +07:00
|
|
|
_getStations();
|
|
|
|
}
|
2024-09-23 18:44:04 +07:00
|
|
|
|
2024-09-23 19:20:07 +07:00
|
|
|
Future<void> _getStations() async {
|
|
|
|
final String stationFile =
|
|
|
|
await rootBundle.loadString("assets/data/stations.json");
|
|
|
|
final data = await json.decode(stationFile);
|
|
|
|
|
2024-09-23 19:37:32 +07:00
|
|
|
setState(() {
|
|
|
|
_stations = data["records"];
|
|
|
|
_getMarkers();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _getMarkers() async {
|
2024-09-23 19:20:07 +07:00
|
|
|
List<Marker> markers = [];
|
2024-09-23 18:44:04 +07:00
|
|
|
|
2024-09-23 19:20:07 +07:00
|
|
|
for (var i = 0; i < _stations.length; i++) {
|
2024-09-23 18:44:04 +07:00
|
|
|
markers.add(
|
|
|
|
Marker(
|
|
|
|
height: 30,
|
|
|
|
width: 30,
|
2024-09-23 19:20:07 +07:00
|
|
|
point: LatLng(double.tryParse(_stations[i][4].toString()) ?? 0,
|
|
|
|
double.tryParse(_stations[i][5].toString()) ?? 0),
|
2024-09-23 19:37:32 +07:00
|
|
|
builder: (ctx) =>
|
|
|
|
const Icon(Icons.pin_drop, color: Colors.brown, size: 50.0),
|
2024-09-23 18:44:04 +07:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(() {
|
2024-09-23 19:20:07 +07:00
|
|
|
_markers = markers;
|
2024-09-23 18:44:04 +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 18:44:04 +07:00
|
|
|
body: FlutterMap(
|
2024-09-23 19:20:07 +07:00
|
|
|
options:
|
2024-09-23 19:37:32 +07:00
|
|
|
MapOptions(center: const LatLng(13.736717, 100.523186), zoom: 10.0),
|
2024-09-23 19:20:07 +07:00
|
|
|
children: [
|
2024-09-23 18:44:04 +07:00
|
|
|
TileLayer(
|
2024-09-23 19:20:07 +07:00
|
|
|
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
2024-09-23 19:37:32 +07:00
|
|
|
//userAgentPackageName: 'net.winscloud.srt',
|
2024-09-23 18:44:04 +07:00
|
|
|
),
|
2024-09-23 19:20:07 +07:00
|
|
|
MarkerLayer(markers: _markers)
|
2024-09-23 18:44:04 +07:00
|
|
|
],
|
|
|
|
),
|
2024-09-23 11:52:20 +07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|