Fix payment server: remove global conRide to prevent crashing non-ride DB queries

This commit is contained in:
Hamza-Ayed
2026-08-01 18:28:30 +03:00
parent 998cad6756
commit f7df080b27
5 changed files with 175 additions and 72 deletions
@@ -187,7 +187,13 @@ class LocationController extends GetxController with WidgetsBindingObserver {
});
socket!.disconnect();
}
return;
}
// ‏أي تغيّر آخر (متاح ⇄ مشغول) يجب أن يصل السيرفر فوراً: هو الحدث الذي
// ‏ينقل الكابتن بين geo:drivers:available و geo:drivers:busy. وبلا هذا
// ‏ننتظر أول حدث GPS — وفلتر المسافة قد يؤجّله دقائق إن كان واقفاً.
_emitCurrentLocationNow();
});
bool deps = await _awaitDependencies();
@@ -349,11 +355,11 @@ class LocationController extends GetxController with WidgetsBindingObserver {
if (sid != null || eid != null) {
isSocketConnected = true;
if (myLocation.latitude != 0) {
print("🚀 Sending initial location to socket after connect...");
emitLocationToSocket(myLocation, heading, speed);
}
// ‏هذا الـ emit هو ما يُسجّل الكابتن في geo:drivers:available بعد كل
// ‏اتصال جديد، فلا نتخطاه لمجرد أن أول تثبيت GPS لم يصل بعد.
print("🚀 Sending initial location to socket after connect...");
_emitCurrentLocationNow();
_startHeartbeat();
// 🆕 طلب أي رحلات انتظار فاتتنا أثناء انقطاع الاتصال
@@ -546,6 +552,30 @@ class LocationController extends GetxController with WidgetsBindingObserver {
_socketHeartbeat?.cancel();
}
/// يبثّ الموقع الحالي فوراً، ويجلب تثبيتاً واحداً إن لم يكن لدينا موقع بعد.
///
/// ضروري بعد كل اتصال جديد وبعد كل تغيّر حالة: ملفّ التتبّع في وضع الانتظار
/// يستخدم فلتر مسافة (50–100 متر)، فالكابتن الواقف قد لا يُصدر أي حدث
/// onLocationChanged إطلاقاً — ولو اعتمدنا عليه وحده لبقي غير مرئي على
/// خريطة الراكب حتى يتحرّك فعلياً.
Future<void> _emitCurrentLocationNow() async {
if (socket == null || !socket!.connected) return;
if (myLocation.latitude == 0 && myLocation.longitude == 0) {
await getLocation();
}
if (myLocation.latitude == 0 && myLocation.longitude == 0) {
Log.print("⚠️ No GPS fix yet — initial location emit skipped.");
return;
}
if (isBusMode) {
emitBusLocationToSocket(myLocation, heading, speed);
} else {
emitLocationToSocket(myLocation, heading, speed);
}
}
// In LocationController.dart
void emitLocationToSocket(LatLng pos, double head, double spd) {