Update: 2026-06-10 18:11:50

This commit is contained in:
Hamza-Ayed
2026-06-10 18:11:50 +03:00
parent a0473a8b0f
commit 977adfe99d
27 changed files with 3946 additions and 206 deletions

View File

@@ -2570,27 +2570,19 @@ class MapDriverController extends GetxController
}
void _startLocationListening() {
_locationSubscription?.cancel();
_locationSubscription = geo.Geolocator.getPositionStream(
locationSettings: const geo.LocationSettings(
accuracy: geo.LocationAccuracy.bestForNavigation,
distanceFilter: 2,
),
).listen((geo.Position pos) {
_handleLocationUpdate(pos);
});
// Location stream is now centralized in LocationController to prevent device hanging.
// LocationController will call handleLocationUpdateFromCentral directly.
}
/// [Fix C-4] تحديث myLocation في المستمع الأساسي
void _handleLocationUpdate(geo.Position pos) {
final newLoc = LatLng(pos.latitude, pos.longitude);
void handleLocationUpdateFromCentral(LatLng newLoc, double posSpeed, double posHeading) {
myLocation = newLoc; // ← [Fix C-4] تحديث الموقع الفوري
_oldLoc = smoothedLocation ?? newLoc;
_targetLoc = newLoc;
_oldHeading = smoothedHeading;
if (pos.speed > 0.5) {
_targetHeading = pos.heading;
if (posSpeed > 0.5) {
_targetHeading = posHeading;
} else {
_targetHeading = _oldHeading;
}

View File

@@ -69,6 +69,7 @@ class OrderRequestController extends GetxController
// --- الخريطة ---
Set<Polyline> polylines = {};
bool _hasCalculatedFullJourney = false;
// حالة التطبيق والصوت
bool isInBackground = false;
@@ -219,6 +220,11 @@ class OrderRequestController extends GetxController
// ----------------------------------------------------------------------
Future<void> _calculateFullJourney() async {
if (_hasCalculatedFullJourney) {
if (mapController != null) zoomToFitRide();
return;
}
_hasCalculatedFullJourney = true;
// Don't block on mapController being null - we'll draw routes
// and markers first, then zoom when controller is ready
bool canZoom = mapController != null;
@@ -281,7 +287,7 @@ class OrderRequestController extends GetxController
totalTripDistance = tripResult['distance_text'];
totalTripDuration = tripResult['duration_text'];
polylines.add(tripResult['polyline']);
// 🔥 تخزين استجابة السيرفر كاملة (بما فيها الـ points والـ instructions)
if (tripResult['raw_response'] != null) {
box.write('cached_trip_route', tripResult['raw_response']);

View File

@@ -476,32 +476,18 @@ class NavigationController extends GetxController
}
void _startLocationStream() {
_locationStreamSubscription?.cancel();
// Listen to location updates with minimum distance filter of 2 meters
// This provides real-time updates without the 3-4 second delay
_locationStreamSubscription = Geolocator.getPositionStream(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 2, // Update every 2 meters
),
).listen(
(Position position) {
_handleLocationUpdate(position);
},
onError: (error) {
Log.print("DEBUG: Location stream error: $error");
},
);
// Location stream is now centralized in LocationController to prevent device hanging.
// LocationController will call handleLocationUpdateFromCentral directly.
}
bool _isProcessing = false;
Future<void> _handleLocationUpdate(Position position) async {
Future<void> handleLocationUpdateFromCentral(LatLng newLoc, double locSpeed, double locHeading) async {
if (_isProcessing) return;
_isProcessing = true;
try {
final newLoc = LatLng(position.latitude, position.longitude);
currentSpeed = position.speed * 3.6; // Convert m/s to km/h
currentSpeed = locSpeed; // Convert m/s to km/h already done by location controller if needed, wait location_controller sends raw speed or km/h? It sends raw speed. So we should * 3.6
currentSpeed = locSpeed * 3.6;
// Skip if movement is too small
if (_lastProcessedLocation != null) {
@@ -544,7 +530,7 @@ class NavigationController extends GetxController
_targetLoc!.longitude,
);
} else {
_targetHeading = position.heading;
_targetHeading = locHeading;
}
_animController?.forward(from: 0.0);