import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/plugin_api.dart'; import 'package:latlong2/latlong.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); } class MapScreen extends StatefulWidget { const MapScreen({Key? key}) : super(key: key); @override State createState() => _MapScreenState(); } class _MapScreenState extends State { List _stations = []; List _markers = []; @override void initState() { super.initState(); _getStations(); } Future _getStations() async { final String stationFile = await rootBundle.loadString("assets/data/stations.json"); final data = await json.decode(stationFile); List 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), ), ); } setState(() { _stations = data["records"]; _markers = markers; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Home'), actions: [ 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)), body: FlutterMap( options: MapOptions(center: const LatLng(13.736717, 100.523186), zoom: 2.0), children: [ TileLayer( urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', userAgentPackageName: 'net.winscloud,net', ), MarkerLayer(markers: _markers) ], ), ); } }