Update: 2026-07-09 03:41:48

This commit is contained in:
Hamza-Ayed
2026-07-09 03:41:48 +03:00
parent 7dff7b6973
commit 70718946f5
10 changed files with 295 additions and 639 deletions
@@ -63,6 +63,9 @@ class RideLifecycleController extends GetxController {
// --- Missing variables from monolithic controller ---
String currentRideId = '';
bool isDrawingRoute = false;
// 🔥 [Fix Race] يمنع استجابة HTTP قديمة (لوجهة سابقة) من الكتابة فوق
// نتيجة أحدث عند تبديل الوجهة بسرعة داخل getDirectionMap.
int _routeRequestGeneration = 0;
bool isAnotherOreder = false;
bool isWhatsAppOrder = false;
LatLng startLocation = const LatLng(32, 35);
@@ -670,6 +673,7 @@ class RideLifecycleController extends GetxController {
if (rideStatusFromStartApp['data'] == null) {
_isReviewProcessed = false;
restCounter();
currentRideState.value = RideState.noRide;
startMasterTimer();
return;
@@ -700,6 +704,9 @@ class RideLifecycleController extends GetxController {
currentRideState.value = RideState.noRide;
startMasterTimer();
} else {
// 🔥 [Fix Polyline] لا حاجة للتقييم — لازم نمسح مسار الرحلة المنتهية
// قبل العودة لحالة noRide، وإلا يبقى ظاهراً على الخريطة الخاملة
restCounter();
currentRideState.value = RideState.noRide;
startMasterTimer();
}
@@ -3508,7 +3515,15 @@ class RideLifecycleController extends GetxController {
}
Future<void> getDirectionMap(String origin, String destination,
[List<String> waypoints = const [], int attemptCount = 0]) async {
[List<String> waypoints = const [],
int attemptCount = 0,
int? gen]) async {
// 🔥 [Fix Race] كل طلب جديد (attemptCount == 0) يفتح "جيلاً" جديداً؛
// إعادة المحاولات (retries) تتبع نفس الجيل. أي استجابة تصل بعد أن بدأ
// جيل أحدث (تبديل وجهة سريع) تُهمَل ولا تكتب فوق الحالة الحالية.
final int myGeneration =
attemptCount == 0 ? (++_routeRequestGeneration) : (gen ?? _routeRequestGeneration);
if (attemptCount == 0) {
isDrawingRoute = true;
update();
@@ -3563,7 +3578,8 @@ class RideLifecycleController extends GetxController {
if (!isRequestValid) {
if (attemptCount < 2) {
await _retryProcess(origin, destination, waypoints, attemptCount);
await _retryProcess(
origin, destination, waypoints, attemptCount, myGeneration);
return;
}
_handleFatalError(
@@ -3571,6 +3587,13 @@ class RideLifecycleController extends GetxController {
return;
}
// 🔥 [Fix Race] وجهة أحدث بدأت طلبها الخاص أثناء انتظار هذا الرد — تجاهل
if (myGeneration != _routeRequestGeneration) {
Log.print(
'🚫 Stale route response ignored (gen $myGeneration != current $_routeRequestGeneration)');
return;
}
double apiDistanceMeters;
String pointsString;
dynamic routeData;
@@ -3593,8 +3616,8 @@ class RideLifecycleController extends GetxController {
if (attemptCount < 2) {
Log.print("🔄 Retrying request (Attempt ${attemptCount + 2})...");
await Future.delayed(const Duration(seconds: 1));
await getDirectionMap(
origin, destination, waypoints, attemptCount + 1);
await getDirectionMap(origin, destination, waypoints,
attemptCount + 1, myGeneration);
return;
} else {
Log.print("❌ All retries failed. Calculating Route is impossible.");
@@ -3628,6 +3651,14 @@ class RideLifecycleController extends GetxController {
return;
}
// 🔥 [Fix Race] فحص ثانٍ بعد فك التشفير في isolate منفصل (compute) —
// قد يكون طلب أحدث بدأ وانتهى خلال هذه الفترة
if (myGeneration != _routeRequestGeneration) {
Log.print(
'🚫 Stale route response ignored after decode (gen $myGeneration != current $_routeRequestGeneration)');
return;
}
mapEngine.polylineCoordinates.clear();
mapEngine.polylineCoordinates.addAll(decodedPoints);
@@ -3758,7 +3789,8 @@ class RideLifecycleController extends GetxController {
Log.print('🚨 STACKTRACE: $stackTrace');
if (attemptCount < 2) {
await _retryProcess(origin, destination, waypoints, attemptCount);
await _retryProcess(
origin, destination, waypoints, attemptCount, myGeneration);
} else {
_handleFatalError("Connection Error".tr,
"Please check your internet and try again.".tr);
@@ -3767,11 +3799,11 @@ class RideLifecycleController extends GetxController {
}
Future<void> _retryProcess(String origin, String dest, List<String> waypoints,
int currentAttempt) async {
int currentAttempt, [int? gen]) async {
Log.print(
"🔄 Exception or Error caught. Retrying in 1s... (Attempt ${currentAttempt + 1})");
await Future.delayed(const Duration(seconds: 1));
getDirectionMap(origin, dest, waypoints, currentAttempt + 1);
getDirectionMap(origin, dest, waypoints, currentAttempt + 1, gen);
}
bool _isUsingFallback = false;