Update: 2026-06-26 04:04:03
This commit is contained in:
@@ -1451,11 +1451,27 @@ class RideLifecycleController extends GetxController {
|
||||
"has_steps": Get.find<WayPointController>().wayPoints.length > 1
|
||||
? 'true'
|
||||
: 'false',
|
||||
"step0": placesCoordinate.length > 0 ? placesCoordinate[0] : "",
|
||||
"step1": placesCoordinate.length > 1 ? placesCoordinate[1] : "",
|
||||
"step2": placesCoordinate.length > 2 ? placesCoordinate[2] : "",
|
||||
"step3": placesCoordinate.length > 3 ? placesCoordinate[3] : "",
|
||||
"step4": placesCoordinate.length > 4 ? placesCoordinate[4] : "",
|
||||
// ✅ FIX P5: إرسال step0-4 فقط عندما has_steps == true
|
||||
"step0": Get.find<WayPointController>().wayPoints.length > 1 &&
|
||||
placesCoordinate.length > 0
|
||||
? placesCoordinate[0]
|
||||
: "",
|
||||
"step1": Get.find<WayPointController>().wayPoints.length > 1 &&
|
||||
placesCoordinate.length > 1
|
||||
? placesCoordinate[1]
|
||||
: "",
|
||||
"step2": Get.find<WayPointController>().wayPoints.length > 1 &&
|
||||
placesCoordinate.length > 2
|
||||
? placesCoordinate[2]
|
||||
: "",
|
||||
"step3": Get.find<WayPointController>().wayPoints.length > 1 &&
|
||||
placesCoordinate.length > 3
|
||||
? placesCoordinate[3]
|
||||
: "",
|
||||
"step4": Get.find<WayPointController>().wayPoints.length > 1 &&
|
||||
placesCoordinate.length > 4
|
||||
? placesCoordinate[4]
|
||||
: "",
|
||||
"price_token": priceToken,
|
||||
};
|
||||
|
||||
@@ -1796,15 +1812,30 @@ class RideLifecycleController extends GetxController {
|
||||
if (!promoFormKey.currentState!.validate()) return;
|
||||
|
||||
try {
|
||||
final String pricingPassengerLat =
|
||||
mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.first.latitude.toString()
|
||||
: newMyLocation.latitude.toString();
|
||||
final String pricingPassengerLng =
|
||||
mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.first.longitude.toString()
|
||||
: newMyLocation.longitude.toString();
|
||||
final String pricingDestLat = mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.last.latitude.toString()
|
||||
: myDestination.latitude.toString();
|
||||
final String pricingDestLng = mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.last.longitude.toString()
|
||||
: myDestination.longitude.toString();
|
||||
|
||||
final res = await CRUD().post(link: AppLink.getPrices, payload: {
|
||||
'distance': distance.toString(),
|
||||
'durationToRide': durationToRide.toString(),
|
||||
'startNameAddress': startNameAddress,
|
||||
'endNameAddress': endNameAddress,
|
||||
'destLat': myDestination.latitude.toString(),
|
||||
'destLng': myDestination.longitude.toString(),
|
||||
'passengerLat': newMyLocation.latitude.toString(),
|
||||
'passengerLng': newMyLocation.longitude.toString(),
|
||||
'destLat': pricingDestLat,
|
||||
'destLng': pricingDestLng,
|
||||
'passengerLat': pricingPassengerLat,
|
||||
'passengerLng': pricingPassengerLng,
|
||||
'walletVal': box.read(BoxName.passengerWalletTotal)?.toString() ?? '0',
|
||||
'activeMenuWaypointCount': activeMenuWaypointCount.toString(),
|
||||
'promo_code': promo.text,
|
||||
@@ -1833,6 +1864,56 @@ class RideLifecycleController extends GetxController {
|
||||
totalPassengerRayehGaiBalash =
|
||||
data['totalPassengerRayehGaiBalash']?.toString() ?? '0';
|
||||
|
||||
priceToken = res['price_token']?.toString() ?? '';
|
||||
|
||||
num appliedDiscount = (res['applied_discount'] ?? 0) is num
|
||||
? res['applied_discount'] ?? 0
|
||||
: num.tryParse(res['applied_discount']?.toString() ?? '0') ?? 0;
|
||||
|
||||
// ✅ FIX P4: إظهار خطأ إذا كان الخصم صفر (برومو غير صالح)
|
||||
if (appliedDiscount <= 0) {
|
||||
Log.print('⚠️ Promo code returned zero discount. Showing error.');
|
||||
MyDialog().getDialog(
|
||||
'Invalid Promo Code'.tr,
|
||||
'This promo code is invalid, expired, or does not apply to your account.'
|
||||
.tr,
|
||||
() => Get.back(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.print('💰 Promo discount applied: $appliedDiscount');
|
||||
|
||||
String carType = box.read(BoxName.carType) ?? '';
|
||||
switch (carType) {
|
||||
case 'Comfort':
|
||||
totalPassenger = totalPassengerComfort;
|
||||
break;
|
||||
case 'Fixed Price':
|
||||
totalPassenger = totalPassengerSpeed;
|
||||
break;
|
||||
case 'Electric':
|
||||
totalPassenger = totalPassengerElectric;
|
||||
break;
|
||||
case 'Awfar Car':
|
||||
totalPassenger = totalPassengerBalash;
|
||||
break;
|
||||
case 'Scooter':
|
||||
case 'Pink Bike':
|
||||
totalPassenger = totalPassengerScooter;
|
||||
break;
|
||||
case 'Van':
|
||||
totalPassenger = totalPassengerVan;
|
||||
break;
|
||||
case 'Lady':
|
||||
totalPassenger = totalPassengerLady;
|
||||
break;
|
||||
case 'Rayeh Gai':
|
||||
totalPassenger = totalPassengerRayehGai;
|
||||
break;
|
||||
}
|
||||
totalCostPassenger = totalPassenger;
|
||||
|
||||
promoTaken = true;
|
||||
update();
|
||||
|
||||
@@ -1872,15 +1953,30 @@ class RideLifecycleController extends GetxController {
|
||||
newTime = currentTime.add(durationToAdd);
|
||||
|
||||
try {
|
||||
final String pricingPassengerLat =
|
||||
mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.first.latitude.toString()
|
||||
: newMyLocation.latitude.toString();
|
||||
final String pricingPassengerLng =
|
||||
mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.first.longitude.toString()
|
||||
: newMyLocation.longitude.toString();
|
||||
final String pricingDestLat = mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.last.latitude.toString()
|
||||
: myDestination.latitude.toString();
|
||||
final String pricingDestLng = mapEngine.polylineCoordinates.isNotEmpty
|
||||
? mapEngine.polylineCoordinates.last.longitude.toString()
|
||||
: myDestination.longitude.toString();
|
||||
|
||||
final res = await CRUD().post(link: AppLink.getPrices, payload: {
|
||||
'distance': distance.toString(),
|
||||
'durationToRide': durationToRide.toString(),
|
||||
'startNameAddress': startNameAddress,
|
||||
'endNameAddress': endNameAddress,
|
||||
'destLat': myDestination.latitude.toString(),
|
||||
'destLng': myDestination.longitude.toString(),
|
||||
'passengerLat': newMyLocation.latitude.toString(),
|
||||
'passengerLng': newMyLocation.longitude.toString(),
|
||||
'destLat': pricingDestLat,
|
||||
'destLng': pricingDestLng,
|
||||
'passengerLat': pricingPassengerLat,
|
||||
'passengerLng': pricingPassengerLng,
|
||||
'walletVal': box.read(BoxName.passengerWalletTotal)?.toString() ?? '0',
|
||||
'activeMenuWaypointCount': activeMenuWaypointCount.toString(),
|
||||
'passenger_id': box.read(BoxName.passengerID) ?? '',
|
||||
@@ -2140,7 +2236,8 @@ class RideLifecycleController extends GetxController {
|
||||
if (statusRide == 'Begin' ||
|
||||
currentRideState.value == RideState.inProgress) {
|
||||
polyLines = {
|
||||
...polyLines.where((p) => !p.polylineId.value.startsWith('driver_route')),
|
||||
...polyLines
|
||||
.where((p) => !p.polylineId.value.startsWith('driver_route')),
|
||||
Polyline(
|
||||
polylineId: const PolylineId('main_route'),
|
||||
points: remainingPoints,
|
||||
@@ -2190,8 +2287,7 @@ class RideLifecycleController extends GetxController {
|
||||
payload: {'driver_id': driverId});
|
||||
|
||||
if (res != 'failure' && res is Map) {
|
||||
if (res['message'] != null &&
|
||||
(res['message'] as List).isNotEmpty) {
|
||||
if (res['message'] != null && (res['message'] as List).isNotEmpty) {
|
||||
var _data = (res['message'] as List)[0];
|
||||
|
||||
LatLng newDriverPos = LatLng(
|
||||
@@ -2225,8 +2321,7 @@ class RideLifecycleController extends GetxController {
|
||||
}
|
||||
}
|
||||
mapEngine.clearMarkersExceptStartEndAndDriver();
|
||||
reloadMarkerDriverCarsLocationToPassengerAfterApplied(
|
||||
res);
|
||||
reloadMarkerDriverCarsLocationToPassengerAfterApplied(res);
|
||||
}
|
||||
}
|
||||
update();
|
||||
@@ -3393,18 +3488,39 @@ class RideLifecycleController extends GetxController {
|
||||
hours = durationToAdd.inHours;
|
||||
minutes = (durationToAdd.inMinutes % 60).round();
|
||||
|
||||
if (polyLines.isNotEmpty) mapEngine.clearPolyline();
|
||||
|
||||
rideConfirm = false;
|
||||
isMarkersShown = true;
|
||||
update();
|
||||
|
||||
await bottomSheet();
|
||||
|
||||
await mapEngine.playRouteAnimation(
|
||||
mapEngine.polylineCoordinates, mapEngine.lastComputedBounds);
|
||||
|
||||
// ✅ FIX P1: انتظار تحميل الأيقونات قبل إنشاء الـ markers
|
||||
// intaleq_maps تتطلب صوراً مسجلة عبر addImage() وليس أصولاً مباشرة
|
||||
if (!mapEngine.isIconsLoaded) {
|
||||
Log.print('⏳ Waiting for map icons to load before placing markers...');
|
||||
for (int i = 0; i < 20 && !mapEngine.isIconsLoaded; i++) {
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ FIX P1: استخدام fromStyleImage مع المعرّفات المسجلة مسبقاً
|
||||
markers = {
|
||||
Marker(
|
||||
markerId: const MarkerId('start'),
|
||||
position: startLoc,
|
||||
icon: InlqBitmap.fromStyleImage('orange_marker'),
|
||||
icon: InlqBitmap.fromStyleImage(mapEngine.startIcon),
|
||||
infoWindow: const InfoWindow(title: 'A'),
|
||||
anchor: const Offset(0.5, 1.0),
|
||||
),
|
||||
Marker(
|
||||
markerId: const MarkerId('end'),
|
||||
position: endLoc,
|
||||
icon: InlqBitmap.fromStyleImage('violet_marker'),
|
||||
icon: InlqBitmap.fromStyleImage(mapEngine.endIcon),
|
||||
infoWindow: const InfoWindow(title: 'B'),
|
||||
anchor: const Offset(0.5, 1.0),
|
||||
),
|
||||
@@ -3418,7 +3534,7 @@ class RideLifecycleController extends GetxController {
|
||||
markerId: MarkerId('waypoint_$i'),
|
||||
position: wp,
|
||||
icon: InlqBitmap.fromStyleImage(
|
||||
isFirstWaypoint ? 'orange_marker' : 'violet_marker'),
|
||||
isFirstWaypoint ? mapEngine.startIcon : mapEngine.endIcon),
|
||||
infoWindow:
|
||||
InfoWindow(title: isFirstWaypoint ? 'Stop 1' : 'Stop 2'),
|
||||
anchor: const Offset(0.5, 1.0),
|
||||
@@ -3426,16 +3542,8 @@ class RideLifecycleController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
if (polyLines.isNotEmpty) mapEngine.clearPolyline();
|
||||
|
||||
rideConfirm = false;
|
||||
isMarkersShown = true;
|
||||
Log.print('✅ FIX P1: Markers placed — start: $startLoc, end: $endLoc');
|
||||
update();
|
||||
|
||||
await bottomSheet();
|
||||
|
||||
await mapEngine.playRouteAnimation(
|
||||
mapEngine.polylineCoordinates, mapEngine.lastComputedBounds);
|
||||
} catch (e, stackTrace) {
|
||||
if (isDrawingRoute) {
|
||||
isDrawingRoute = false;
|
||||
@@ -4034,23 +4142,26 @@ class RideLifecycleController extends GetxController {
|
||||
await _checkAndRefreshMapStyle();
|
||||
Get.put(DeepLinkController(), permanent: true);
|
||||
await initilizeGetStorage();
|
||||
|
||||
final bool isLoggedIn = box.read(BoxName.isVerified) == '1' &&
|
||||
box.read(BoxName.passengerID) != null;
|
||||
|
||||
|
||||
final bool isLoggedIn = box.read(BoxName.isVerified) == '1' &&
|
||||
box.read(BoxName.passengerID) != null;
|
||||
|
||||
// We intentionally DO NOT initialize data here during onInit
|
||||
// because this controller is instantiated globally before the map is opened.
|
||||
// Initialization will be triggered by MapPagePassenger calling initializeDataAfterLogin()
|
||||
Log.print("RideLifecycleController.onInit: Waiting for MapPagePassenger to trigger initialization.");
|
||||
Log.print(
|
||||
"RideLifecycleController.onInit: Waiting for MapPagePassenger to trigger initialization.");
|
||||
}
|
||||
|
||||
Future<void> initializeDataAfterLogin() async {
|
||||
if (isDataInitializedAfterLogin) {
|
||||
Log.print("RideLifecycleController: Already initialized, skipping duplicate initializeDataAfterLogin.");
|
||||
Log.print(
|
||||
"RideLifecycleController: Already initialized, skipping duplicate initializeDataAfterLogin.");
|
||||
return;
|
||||
}
|
||||
isDataInitializedAfterLogin = true;
|
||||
Log.print("RideLifecycleController: Initializing data after successful login...");
|
||||
Log.print(
|
||||
"RideLifecycleController: Initializing data after successful login...");
|
||||
getLocationArea(passengerLocation.latitude, passengerLocation.longitude);
|
||||
await _stagePricingAndState();
|
||||
await _stageNiceToHave();
|
||||
|
||||
Reference in New Issue
Block a user