Implemented proper map popup with navigation
This commit is contained in:
@@ -8,6 +8,8 @@ import 'package:provider/provider.dart';
|
|||||||
import '../model/flood_station.dart';
|
import '../model/flood_station.dart';
|
||||||
import '../services/flood_station_provider.dart';
|
import '../services/flood_station_provider.dart';
|
||||||
import '../widgets/custom_marker.dart';
|
import '../widgets/custom_marker.dart';
|
||||||
|
import '../widgets/map_popup.dart';
|
||||||
|
import 'flood_station_page.dart';
|
||||||
|
|
||||||
class MapPage extends StatefulWidget {
|
class MapPage extends StatefulWidget {
|
||||||
const MapPage({super.key});
|
const MapPage({super.key});
|
||||||
@@ -19,14 +21,15 @@ class MapPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _MapPageState extends State<MapPage> {
|
class _MapPageState extends State<MapPage> {
|
||||||
final mapController = MapController();
|
final mapController = MapController();
|
||||||
|
late FloodStationProvider _floodStationProvider;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final floodStationProvider = context.watch<FloodStationProvider>();
|
_floodStationProvider = context.watch<FloodStationProvider>();
|
||||||
if (floodStationProvider.allStations.isEmpty) {
|
if (_floodStationProvider.allStations.isEmpty) {
|
||||||
return Center(
|
return Center(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: floodStationProvider.loadAllStations,
|
onPressed: _floodStationProvider.loadAllStations,
|
||||||
child: Text('Load Map'),
|
child: Text('Load Map'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -35,7 +38,7 @@ class _MapPageState extends State<MapPage> {
|
|||||||
mapController: mapController,
|
mapController: mapController,
|
||||||
options: MapOptions(
|
options: MapOptions(
|
||||||
cameraConstraint: CameraConstraint.containCenter(
|
cameraConstraint: CameraConstraint.containCenter(
|
||||||
bounds: LatLngBounds.fromPoints(floodStationProvider.allStations
|
bounds: LatLngBounds.fromPoints(_floodStationProvider.allStations
|
||||||
.map<LatLng>(
|
.map<LatLng>(
|
||||||
(e) => LatLng(e.lat, e.long),
|
(e) => LatLng(e.lat, e.long),
|
||||||
)
|
)
|
||||||
@@ -52,7 +55,7 @@ class _MapPageState extends State<MapPage> {
|
|||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
padding: EdgeInsets.all(50),
|
padding: EdgeInsets.all(50),
|
||||||
maxZoom: 15,
|
maxZoom: 15,
|
||||||
markers: _stationsAsMarkers(floodStationProvider.allStations),
|
markers: _stationsAsMarkers(_floodStationProvider.allStations),
|
||||||
builder: _markerBuilder),
|
builder: _markerBuilder),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@@ -91,17 +94,12 @@ class _MapPageState extends State<MapPage> {
|
|||||||
_markerTapped(FloodStation station) {
|
_markerTapped(FloodStation station) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) => MapPopup(
|
||||||
return Center(
|
station: station,
|
||||||
child: Card(
|
onShowTapped: () {
|
||||||
child: SizedBox(
|
_floodStationProvider.selectedStation = station;
|
||||||
width: 300,
|
Navigator.of(context).pushNamed(FloodStationPage.routeName);
|
||||||
height: 300,
|
}),
|
||||||
child: Text(station.label),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
60
lib/widgets/map_popup.dart
Normal file
60
lib/widgets/map_popup.dart
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart' as intl;
|
||||||
|
|
||||||
|
import '../model/flood_station.dart';
|
||||||
|
|
||||||
|
class MapPopup extends StatelessWidget {
|
||||||
|
const MapPopup(
|
||||||
|
{super.key, required this.station, required this.onShowTapped});
|
||||||
|
final FloodStation station;
|
||||||
|
final Function() onShowTapped;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(station.label),
|
||||||
|
content: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.home_outlined),
|
||||||
|
Padding(padding: EdgeInsets.only(left: 8)),
|
||||||
|
Text(station.town.isEmpty ? '-' : station.town),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.water),
|
||||||
|
Padding(padding: EdgeInsets.only(left: 8)),
|
||||||
|
Text(station.riverName.isEmpty ? '-' : station.riverName),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.calendar_month_outlined),
|
||||||
|
Padding(padding: EdgeInsets.only(left: 8)),
|
||||||
|
Text(
|
||||||
|
station.dateOpened != null
|
||||||
|
? intl.DateFormat.yMd().format(station.dateOpened!)
|
||||||
|
: '-',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
child: Text('dismiss'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: onShowTapped,
|
||||||
|
child: Text('show'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user