This repository has been archived on 2024-04-18. You can view files and clone it, but cannot push or open issues or pull requests.
app/lib/state/mapState.dart

38 lines
1.1 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:geolocator/geolocator.dart';
import 'package:latlong2/latlong.dart';
class MapState extends ChangeNotifier {
bool _isLocationLive = false;
LatLng? _currentLocation;
LatLng? _activeMarker;
final MapController _mapController = MapController();
final Geolocator _geolocator = Geolocator();
bool get isLocationLive => _isLocationLive;
LatLng? get getCurrentLocation => _currentLocation;
LatLng? get getActiveMarker => _activeMarker;
MapController get getMapController => _mapController;
Geolocator get getGeolocator => _geolocator;
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 setLocationLive(bool live) {
_isLocationLive = live;
notifyListeners();
}
}