diff --git a/lib/state/mapState.dart b/lib/state/mapState.dart index 69a6e90..8f33ed2 100644 --- a/lib/state/mapState.dart +++ b/lib/state/mapState.dart @@ -5,15 +5,22 @@ import 'package:latlong2/latlong.dart'; class MapState extends ChangeNotifier { bool _isCurrentlyLoading = false; + LatLng? _currentLocation; LatLng? _activeMarker; final MapController _mapController = MapController(); final Geolocator _geolocator = Geolocator(); bool get isCurrentlyLoading => _isCurrentlyLoading; + LatLng? get getCurrentLocation => _currentLocation; LatLng? get getActiveMarker => _activeMarker; MapController get getMapController => _mapController; Geolocator get getGeolocator => _geolocator; + void setCurrentLocation(LatLng? currentLocation) { + _currentLocation = currentLocation; + notifyListeners(); + } + void setActiveMarker(LatLng? marker) { _activeMarker = marker; notifyListeners(); diff --git a/lib/view/home.dart b/lib/view/home.dart index dc8c78e..8fbd9f5 100644 --- a/lib/view/home.dart +++ b/lib/view/home.dart @@ -105,6 +105,7 @@ class _HomePageState extends State<HomeView> { mapState.setLoading(true); LatLng? latLng = await getLatLng(); if (latLng != null) { + mapState.setCurrentLocation(latLng); mapState.getMapController.move(latLng, 16); } mapState.setLoading(false); diff --git a/lib/view/map.dart b/lib/view/map.dart index 683c46f..5f17b5a 100644 --- a/lib/view/map.dart +++ b/lib/view/map.dart @@ -1,6 +1,7 @@ import 'package:app/extensions/obtainProviderExtension.dart'; import 'package:app/state/mapState.dart'; import 'package:app/util/watchState.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:http/http.dart'; @@ -49,7 +50,37 @@ class _MapViewState extends State<MapView> { ) ) ], - ) : const SizedBox.shrink()) + ) : const SizedBox.shrink()), + WatchState<MapState>((context, state) => MarkerLayer( + markers: [ + if (state.getActiveMarker != null) Marker( + point: state.getActiveMarker!, + child: const Icon( + Icons.location_on, + color: Colors.red, + size: 48, + ) + ), + if (state.getCurrentLocation != null) Marker( + point: state.getCurrentLocation!, + child: const Stack( + alignment: Alignment.center, + children: [ + Icon( + Icons.circle, + color: Colors.white, + size: 23, + ), + Icon( + Icons.circle, + color: Color.fromARGB(255, 0, 200, 0), + size: 16, + ) + ], + ) + ) + ] + )) ], ); }