new changes maps
This commit is contained in:
@@ -19,12 +19,15 @@ class _RiderNavigationScreen extends StatefulWidget {
|
||||
|
||||
class _RiderNavigationScreenState extends State<_RiderNavigationScreen>
|
||||
with WidgetsBindingObserver {
|
||||
GoogleMapController? mapController;
|
||||
NearleMapController? mapController;
|
||||
bool _mapReady = false;
|
||||
bool _isDisposed = false;
|
||||
Position? _currentPosition;
|
||||
StreamSubscription<Position>? _positionStream;
|
||||
final Set<Marker> _markers = {};
|
||||
List<NearleMapMarker> _markers = const [];
|
||||
MarkerIcon? _riderIcon;
|
||||
MarkerIcon? _dropIcon;
|
||||
LatLng? _lastRiderPosition;
|
||||
late final LatLng dropLocation;
|
||||
bool _isInitializing = true;
|
||||
bool _hasOpenedGoogleMaps = false;
|
||||
@@ -46,6 +49,7 @@ class _RiderNavigationScreenState extends State<_RiderNavigationScreen>
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_resolveDropFromDelivery();
|
||||
_loadMarkerIcons();
|
||||
_initializeMap();
|
||||
_initEtaForNav();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
@@ -214,8 +218,8 @@ class _RiderNavigationScreenState extends State<_RiderNavigationScreen>
|
||||
if (lastPos != null && mounted) {
|
||||
setState(() {
|
||||
_currentPosition = lastPos;
|
||||
_addMarkers(LatLng(lastPos.latitude, lastPos.longitude));
|
||||
});
|
||||
_addMarkers(LatLng(lastPos.latitude, lastPos.longitude));
|
||||
_startLiveTracking();
|
||||
}
|
||||
});
|
||||
@@ -338,8 +342,8 @@ class _RiderNavigationScreenState extends State<_RiderNavigationScreen>
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_currentPosition = position;
|
||||
_addMarkers(LatLng(position.latitude, position.longitude));
|
||||
});
|
||||
_addMarkers(LatLng(position.latitude, position.longitude));
|
||||
|
||||
final distance = Geolocator.distanceBetween(
|
||||
position.latitude,
|
||||
@@ -362,27 +366,36 @@ class _RiderNavigationScreenState extends State<_RiderNavigationScreen>
|
||||
});
|
||||
}
|
||||
|
||||
/// Marker bitmaps are drawn on a canvas, so they arrive asynchronously.
|
||||
/// Once they land, rebuild whatever markers are already pending.
|
||||
Future<void> _loadMarkerIcons() async {
|
||||
final rider = await MapMarkerIcons.dot(Colors.blueAccent);
|
||||
final drop = await MapMarkerIcons.pin(Colors.red);
|
||||
if (!mounted || _isDisposed) return;
|
||||
setState(() {
|
||||
_riderIcon = rider;
|
||||
_dropIcon = drop;
|
||||
_addMarkers(_lastRiderPosition ?? dropLocation);
|
||||
});
|
||||
}
|
||||
|
||||
/// Mutates [_markers] only — callers own the [setState] so this can be
|
||||
/// invoked from inside an existing one without nesting.
|
||||
void _addMarkers(LatLng riderPos) {
|
||||
_markers
|
||||
..clear()
|
||||
..add(
|
||||
Marker(
|
||||
markerId: const MarkerId('rider'),
|
||||
position: riderPos,
|
||||
icon: BitmapDescriptor.defaultMarkerWithHue(
|
||||
BitmapDescriptor.hueAzure,
|
||||
),
|
||||
infoWindow: const InfoWindow(title: 'You (Rider)'),
|
||||
),
|
||||
)
|
||||
..add(
|
||||
Marker(
|
||||
markerId: const MarkerId('drop'),
|
||||
position: dropLocation,
|
||||
icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueRed),
|
||||
infoWindow: const InfoWindow(title: 'Drop Location'),
|
||||
),
|
||||
);
|
||||
_lastRiderPosition = riderPos;
|
||||
final riderIcon = _riderIcon;
|
||||
final dropIcon = _dropIcon;
|
||||
if (riderIcon == null || dropIcon == null) return;
|
||||
|
||||
_markers = [
|
||||
NearleMapMarker(
|
||||
id: 'rider',
|
||||
position: riderPos,
|
||||
icon: riderIcon,
|
||||
anchor: MarkerAnchor.center,
|
||||
),
|
||||
NearleMapMarker(id: 'drop', position: dropLocation, icon: dropIcon),
|
||||
];
|
||||
}
|
||||
|
||||
Future<void> _attemptAutoOpenNavigation({bool fromTimer = false}) async {
|
||||
@@ -511,9 +524,8 @@ class _RiderNavigationScreenState extends State<_RiderNavigationScreen>
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
GoogleMap(
|
||||
mapType: MapType.normal,
|
||||
onMapCreated: (controller) {
|
||||
NearleMap(
|
||||
onMapReady: (controller) {
|
||||
mapController = controller;
|
||||
_mapReady = true;
|
||||
},
|
||||
@@ -527,10 +539,7 @@ class _RiderNavigationScreenState extends State<_RiderNavigationScreen>
|
||||
),
|
||||
markers: _markers,
|
||||
myLocationEnabled: true,
|
||||
myLocationButtonEnabled: false,
|
||||
trafficEnabled: true,
|
||||
compassEnabled: true,
|
||||
buildingsEnabled: true,
|
||||
tiltGesturesEnabled: true,
|
||||
),
|
||||
if (!_hasOpenedGoogleMaps)
|
||||
@@ -994,11 +1003,7 @@ class _RiderNavigationScreenState extends State<_RiderNavigationScreen>
|
||||
}
|
||||
|
||||
void _safeAnimateCamera(CameraUpdate update) {
|
||||
if (!_mapReady || _isDisposed || mapController == null) return;
|
||||
try {
|
||||
mapController?.animateCamera(update);
|
||||
} catch (e) {
|
||||
debugPrint('[NAVIGATION] animateCamera skipped: $e');
|
||||
}
|
||||
if (!_mapReady || _isDisposed) return;
|
||||
mapController?.animateCamera(update);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user