Update: 2026-07-02 05:27:04
This commit is contained in:
@@ -1947,6 +1947,15 @@ class RideLifecycleController extends GetxController {
|
||||
|
||||
double costForDriver = 0;
|
||||
|
||||
// ─── بيانات مقارنة أسعار المنافسين ───
|
||||
bool hasCompetitorData = false;
|
||||
double? competitorAvgPrice;
|
||||
double? savingsPercent;
|
||||
String? savingsLabel;
|
||||
String? topCompetitor;
|
||||
String? driverExtraLabel;
|
||||
double? driverExtraAmount;
|
||||
|
||||
Future bottomSheet() async {
|
||||
durationToAdd = Duration(seconds: durationToRide);
|
||||
hours = durationToAdd.inHours;
|
||||
@@ -2019,6 +2028,46 @@ class RideLifecycleController extends GetxController {
|
||||
|
||||
update();
|
||||
mapEngine.changeBottomSheetShown(forceValue: true);
|
||||
|
||||
// جلب مقارنة أسعار المنافسين في الخلفية بعد عرض الأسعار
|
||||
fetchCompetitorContext();
|
||||
}
|
||||
|
||||
/// يجلب مقارنة سعر سيرو مع المنافسين ويحدّث الواجهة بشكل غير مُوقِف
|
||||
Future<void> fetchCompetitorContext() async {
|
||||
try {
|
||||
final String passengerLat = mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.first.latitude.toString()
|
||||
: newMyLocation.latitude.toString();
|
||||
final String passengerLng = mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.first.longitude.toString()
|
||||
: newMyLocation.longitude.toString();
|
||||
|
||||
final res = await CRUD().post(
|
||||
link: AppLink.getCompetitorContext,
|
||||
payload: {
|
||||
'passenger_lat': passengerLat,
|
||||
'passenger_lng': passengerLng,
|
||||
'distance': distance.toString(),
|
||||
'country': box.read(BoxName.countryCode) ?? '',
|
||||
'siro_price': totalPassengerSpeed,
|
||||
'car_type': 'Speed',
|
||||
},
|
||||
);
|
||||
|
||||
if (res is Map && res['status'] == 'success') {
|
||||
hasCompetitorData = res['has_competitor_data'] == true;
|
||||
competitorAvgPrice = double.tryParse(res['competitor_avg_price']?.toString() ?? '');
|
||||
savingsPercent = double.tryParse(res['savings_percent']?.toString() ?? '');
|
||||
savingsLabel = res['savings_label']?.toString();
|
||||
topCompetitor = res['top_competitor']?.toString();
|
||||
driverExtraLabel = res['driver_extra_label']?.toString();
|
||||
driverExtraAmount = double.tryParse(res['driver_extra_amount']?.toString() ?? '');
|
||||
update();
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('[CompetitorContext] fetch failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// حساب المسار بين السائق والراكب وعرضه على الخريطة.
|
||||
@@ -2426,7 +2475,12 @@ class RideLifecycleController extends GetxController {
|
||||
double tripDurationInMinutes = durationToPassenger / 5;
|
||||
int loopCount = tripDurationInMinutes.ceil();
|
||||
for (var i = 0; i < loopCount; i++) {
|
||||
// [Fix Loop-1] فحص إغلاق الكنترولر قبل وبعد التأخير لمنع crash
|
||||
if (isClosed ||
|
||||
currentRideState.value == RideState.finished ||
|
||||
currentRideState.value == RideState.preCheckReview) return;
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
if (isClosed) return;
|
||||
if (rideTimerBegin == true || statusRide == 'Apply') {
|
||||
await getDriverCarsLocationToPassengerAfterApplied();
|
||||
}
|
||||
@@ -2438,7 +2492,12 @@ class RideLifecycleController extends GetxController {
|
||||
int loopCount = tripDurationInMinutes.ceil();
|
||||
mapEngine.clearMarkersExceptStartEndAndDriver();
|
||||
for (var i = 0; i < loopCount; i++) {
|
||||
// [Fix Loop-2] فحص إغلاق الكنترولر لمنع استدعاء الدوال على كنترولر مغلق
|
||||
if (isClosed ||
|
||||
currentRideState.value == RideState.finished ||
|
||||
currentRideState.value == RideState.preCheckReview) return;
|
||||
await Future.delayed(const Duration(seconds: 4));
|
||||
if (isClosed) return;
|
||||
await getDriverCarsLocationToPassengerAfterApplied();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user