added current location marker
This commit is contained in:
parent
e748df092c
commit
c8278656cf
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
]
|
||||
))
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user