mimic google behavior with location icon button

This commit is contained in:
2024-03-27 22:08:09 +01:00
parent 507b321311
commit 32c88fa857
4 changed files with 89 additions and 58 deletions

View File

@ -4,13 +4,13 @@ import 'package:geolocator/geolocator.dart';
import 'package:latlong2/latlong.dart';
class MapState extends ChangeNotifier {
bool _isCurrentlyLoading = false;
bool _isLocationLive = false;
LatLng? _currentLocation;
LatLng? _activeMarker;
final MapController _mapController = MapController();
final Geolocator _geolocator = Geolocator();
bool get isCurrentlyLoading => _isCurrentlyLoading;
bool get isLocationLive => _isLocationLive;
LatLng? get getCurrentLocation => _currentLocation;
LatLng? get getActiveMarker => _activeMarker;
MapController get getMapController => _mapController;
@ -18,16 +18,21 @@ class MapState extends ChangeNotifier {
void setCurrentLocation(LatLng? currentLocation) {
_currentLocation = currentLocation;
if (currentLocation != null) _mapController.move(currentLocation, 16);
notifyListeners();
}
void setActiveMarker(LatLng? marker) {
_activeMarker = marker;
if (marker != null) {
_isLocationLive = false;
_mapController.move(marker, 16);
}
notifyListeners();
}
void setLoading(bool loading) {
_isCurrentlyLoading = loading;
void setLocationLive(bool live) {
_isLocationLive = live;
notifyListeners();
}
}