12/17/1
This commit is contained in:
@@ -407,7 +407,7 @@ class MapPassengerController extends GetxController {
|
||||
box.read(BoxName.carType), 4000);
|
||||
// confirmRideForAllDriverAvailable();
|
||||
|
||||
icreaseForSameRideAndDelay();
|
||||
increaseForSameRideAndDelay();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -932,13 +932,14 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void tripFinishedFromDriver() async {
|
||||
void tripFinishedFromDriver() {
|
||||
isRideFinished = true;
|
||||
rideTimerBegin = false;
|
||||
statusRideVip = 'Finished';
|
||||
box.write(BoxName.arrivalTime, '');
|
||||
remainingTimeTimerRideBegin = 0;
|
||||
box.write(BoxName.passengerWalletTotal, '0');
|
||||
update();
|
||||
if (box.read(BoxName.parentTripSelected) == true) {
|
||||
FirebaseMessagesController().sendNotificationToPassengerToken(
|
||||
"Finish Monitor".tr,
|
||||
@@ -950,7 +951,6 @@ class MapPassengerController extends GetxController {
|
||||
box.write(BoxName.parentTripSelected, false);
|
||||
box.remove(BoxName.tokenParent);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
// bool isBeginRideFromDriver = false;
|
||||
@@ -998,6 +998,8 @@ class MapPassengerController extends GetxController {
|
||||
try {
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.getRideStatusBegin, payload: {'ride_id': rideId});
|
||||
print(res);
|
||||
print('1002');
|
||||
if (res != 'failure') {
|
||||
var decode = jsonDecode(res);
|
||||
_beginRideStreamController
|
||||
@@ -1067,6 +1069,8 @@ class MapPassengerController extends GetxController {
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.getRideStatusFromStartApp,
|
||||
payload: {'passenger_id': box.read(BoxName.passengerID)});
|
||||
print(res);
|
||||
print('1070');
|
||||
if (res == 'failure') {
|
||||
print(
|
||||
"No rides found for the given passenger ID within the last hour.");
|
||||
@@ -1330,7 +1334,7 @@ class MapPassengerController extends GetxController {
|
||||
|
||||
Set<String> notifiedDrivers = {};
|
||||
|
||||
addRideToNotificationDriverString() async {
|
||||
addRideToNotificationDriverAvailable() async {
|
||||
await CRUD().post(link: AppLink.addWaitingRide, payload: {
|
||||
'id': rideId.toString(),
|
||||
'start_location':
|
||||
@@ -1343,11 +1347,12 @@ class MapPassengerController extends GetxController {
|
||||
'passenger_id': box.read(BoxName.passengerID).toString(),
|
||||
'status': 'waiting',
|
||||
'carType': box.read(BoxName.carType),
|
||||
'passengerRate': passengerRate,
|
||||
'price_for_passenger': totalME.toString(),
|
||||
'distance': distance.toString(),
|
||||
'duration': duration ?? '10',
|
||||
'passengerRate': passengerRate.toStringAsFixed(2),
|
||||
'price_for_passenger': totalME.toStringAsFixed(2),
|
||||
'distance': distance.toStringAsFixed(1),
|
||||
'duration': duration.toStringAsFixed(1),
|
||||
});
|
||||
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(
|
||||
link: '${AppLink.endPoint}/notificationCaptain/addWaitingRide.php',
|
||||
@@ -1363,10 +1368,10 @@ class MapPassengerController extends GetxController {
|
||||
'passenger_id': box.read(BoxName.passengerID).toString(),
|
||||
'status': 'waiting',
|
||||
'carType': box.read(BoxName.carType),
|
||||
'passengerRate': passengerRate,
|
||||
'price_for_passenger': totalME.toString(),
|
||||
'distance': distance.toString(),
|
||||
'duration': duration ?? '10',
|
||||
'passengerRate': passengerRate.toStringAsFixed(2),
|
||||
'price_for_passenger': totalME.toStringAsFixed(2),
|
||||
'distance': distance.toStringAsFixed(1),
|
||||
'duration': duration.toStringAsFixed(0),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1382,7 +1387,7 @@ class MapPassengerController extends GetxController {
|
||||
// if (dataCarsLocationByPassenger != 'failure' &&
|
||||
// dataCarsLocationByPassenger != null &&
|
||||
// dataCarsLocationByPassenger.containsKey('data') &&
|
||||
// dataCarsLocationByPassenger['data'] != null) {
|
||||
// dataCarsLocationByPassenger['message'] != null) {
|
||||
// driversFound = true;
|
||||
// break; // Exit loop if drivers are found
|
||||
// }
|
||||
@@ -1445,7 +1450,7 @@ class MapPassengerController extends GetxController {
|
||||
// "endtime": durationToAdd.toString(),
|
||||
// "price": totalPassenger.toStringAsFixed(2),
|
||||
// "passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
// "driver_id": dataCarsLocationByPassenger['data'][carsOrder]['driver_id']
|
||||
// "driver_id": dataCarsLocationByPassenger['message'][carsOrder]['driver_id']
|
||||
// .toString(),
|
||||
// "status": "waiting",
|
||||
// 'carType': box.read(BoxName.carType),
|
||||
@@ -1477,8 +1482,8 @@ class MapPassengerController extends GetxController {
|
||||
// box.read(BoxName.carType), 3000);
|
||||
// if (dataCarsLocationByPassenger != null &&
|
||||
// dataCarsLocationByPassenger.containsKey('data') &&
|
||||
// dataCarsLocationByPassenger['data'] != null) {
|
||||
// for (var driverData in dataCarsLocationByPassenger['data']) {
|
||||
// dataCarsLocationByPassenger['message'] != null) {
|
||||
// for (var driverData in dataCarsLocationByPassenger['message']) {
|
||||
// String driverId = driverData['driver_id'].toString();
|
||||
// if (!notifiedDrivers.contains(driverId)) {
|
||||
// notifiedDrivers.add(driverId);
|
||||
@@ -1549,7 +1554,7 @@ class MapPassengerController extends GetxController {
|
||||
// "endtime": durationToAdd.toString(),
|
||||
// "price": totalPassenger.toStringAsFixed(2),
|
||||
// "passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
// "driver_id": dataCarsLocationByPassenger['data'][carsOrder]['driver_id']
|
||||
// "driver_id": dataCarsLocationByPassenger['message'][carsOrder]['driver_id']
|
||||
// .toString(),
|
||||
// "status": "waiting",
|
||||
// 'carType': box.read(BoxName.carType),
|
||||
@@ -1563,116 +1568,117 @@ class MapPassengerController extends GetxController {
|
||||
// update();
|
||||
// }
|
||||
|
||||
icreaseForSameRideAndDelay() async {
|
||||
bool driversFound = false;
|
||||
for (int attempt = 0; attempt < 8; attempt++) {
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 4500);
|
||||
increaseForSameRideAndDelay() async {
|
||||
reSearchAfterCanceledFromDriver();
|
||||
// bool driversFound = false;
|
||||
// for (int attempt = 0; attempt < 8; attempt++) {
|
||||
// await getCarsLocationByPassengerAndReloadMarker(
|
||||
// box.read(BoxName.carType), 4500);
|
||||
|
||||
// Check if dataCarsLocationByPassenger is valid and contains drivers
|
||||
if (dataCarsLocationByPassenger != 'failure' &&
|
||||
dataCarsLocationByPassenger != null &&
|
||||
dataCarsLocationByPassenger.containsKey('data') &&
|
||||
dataCarsLocationByPassenger['data'] != null) {
|
||||
driversFound = true;
|
||||
break; // Exit loop if drivers are found
|
||||
}
|
||||
// // Check if dataCarsLocationByPassenger is valid and contains drivers
|
||||
// if (dataCarsLocationByPassenger != 'failure' &&
|
||||
// dataCarsLocationByPassenger != null &&
|
||||
// dataCarsLocationByPassenger.containsKey('message') &&
|
||||
// dataCarsLocationByPassenger['message'] != null) {
|
||||
// driversFound = true;
|
||||
// break; // Exit loop if drivers are found
|
||||
// }
|
||||
|
||||
// Wait 2 seconds before next attempt
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
}
|
||||
// // Wait 2 seconds before next attempt
|
||||
// await Future.delayed(const Duration(seconds: 2));
|
||||
// }
|
||||
|
||||
// If no drivers were found after 4 attempts, show a dialog
|
||||
if (!driversFound) {
|
||||
Get.dialog(
|
||||
BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
|
||||
child: CupertinoAlertDialog(
|
||||
title: Text(
|
||||
"No Car or Driver Found in your area.".tr,
|
||||
style: AppStyle.title.copyWith(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
"No Car or Driver Found in your area.".tr,
|
||||
style: AppStyle.title.copyWith(fontSize: 16),
|
||||
),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
Get.offAll(() => const MapPagePassenger());
|
||||
},
|
||||
child: Text('OK'.tr,
|
||||
style: const TextStyle(color: AppColor.greenColor)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
// // If no drivers were found after 4 attempts, show a dialog
|
||||
// if (!driversFound) {
|
||||
// Get.dialog(
|
||||
// BackdropFilter(
|
||||
// filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
|
||||
// child: CupertinoAlertDialog(
|
||||
// title: Text(
|
||||
// "No Car or Driver Found in your area.".tr,
|
||||
// style: AppStyle.title.copyWith(
|
||||
// fontSize: 20,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
// content: Text(
|
||||
// "No Car or Driver Found in your area.".tr,
|
||||
// style: AppStyle.title.copyWith(fontSize: 16),
|
||||
// ),
|
||||
// actions: [
|
||||
// CupertinoDialogAction(
|
||||
// onPressed: () {
|
||||
// Get.back();
|
||||
// Get.offAll(() => const MapPagePassenger());
|
||||
// },
|
||||
// child: Text('OK'.tr,
|
||||
// style: const TextStyle(color: AppColor.greenColor)),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// barrierDismissible: false,
|
||||
// );
|
||||
|
||||
return;
|
||||
}
|
||||
PaymentController paymentController = Get.find<PaymentController>();
|
||||
rideConfirm = true;
|
||||
shouldFetch = true;
|
||||
isBottomSheetShown = false;
|
||||
timeToPassengerFromDriverAfterApplied = 60;
|
||||
// confirmRideForAllDriverAvailable();
|
||||
for (var i = 0; i < dataCarsLocationByPassenger['data'].length; i++) {
|
||||
List<String> body = [
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
totalPassenger.toStringAsFixed(2),
|
||||
totalDriver.toStringAsFixed(2),
|
||||
durationToRide.toString(),
|
||||
distance.toStringAsFixed(2),
|
||||
dataCarsLocationByPassenger['data'][i]['driver_id'].toString(),
|
||||
box.read(BoxName.passengerID).toString(),
|
||||
box.read(BoxName.name).toString(),
|
||||
box.read(BoxName.tokenFCM).toString(),
|
||||
box.read(BoxName.phone).toString(),
|
||||
durationByPassenger.toString(),
|
||||
distanceByPassenger.toString(),
|
||||
paymentController.isWalletChecked.toString(),
|
||||
dataCarsLocationByPassenger['data'][i]['token'].toString(),
|
||||
durationToPassenger.toString(),
|
||||
rideId.toString(),
|
||||
rideTimerBegin.toString(),
|
||||
dataCarsLocationByPassenger['data'][i]['driver_id'].toString(),
|
||||
durationToRide.toString(),
|
||||
Get.find<WayPointController>().wayPoints.length > 1
|
||||
? 'haveSteps'
|
||||
: 'startEnd',
|
||||
placesCoordinate[0],
|
||||
placesCoordinate[1],
|
||||
placesCoordinate[2],
|
||||
placesCoordinate[3],
|
||||
placesCoordinate[4],
|
||||
costForDriver.toStringAsFixed(2),
|
||||
double.parse(box.read(BoxName.passengerWalletTotal)) < 0
|
||||
? double.parse(box.read(BoxName.passengerWalletTotal))
|
||||
.toStringAsFixed(2)
|
||||
: '0',
|
||||
box.read(BoxName.email).toString(),
|
||||
data[0]['start_address'],
|
||||
data[0]['end_address'],
|
||||
box.read(BoxName.carType),
|
||||
kazan.toStringAsFixed(0),
|
||||
passengerRate.toStringAsFixed(2),
|
||||
];
|
||||
// Log.print('body: ${body}');
|
||||
// return;
|
||||
// }
|
||||
// PaymentController paymentController = Get.find<PaymentController>();
|
||||
// rideConfirm = true;
|
||||
// shouldFetch = true;
|
||||
// isBottomSheetShown = false;
|
||||
// timeToPassengerFromDriverAfterApplied = 60;
|
||||
// // confirmRideForAllDriverAvailable();
|
||||
// for (var i = 0; i < dataCarsLocationByPassenger['message'].length; i++) {
|
||||
// List<String> body = [
|
||||
// '${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
// '${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
// totalPassenger.toStringAsFixed(2),
|
||||
// totalDriver.toStringAsFixed(2),
|
||||
// durationToRide.toString(),
|
||||
// distance.toStringAsFixed(2),
|
||||
// dataCarsLocationByPassenger['message'][i]['driver_id'].toString(),
|
||||
// box.read(BoxName.passengerID).toString(),
|
||||
// box.read(BoxName.name).toString(),
|
||||
// box.read(BoxName.tokenFCM).toString(),
|
||||
// box.read(BoxName.phone).toString(),
|
||||
// durationByPassenger.toString(),
|
||||
// distanceByPassenger.toString(),
|
||||
// paymentController.isWalletChecked.toString(),
|
||||
// dataCarsLocationByPassenger['message'][i]['token'].toString(),
|
||||
// durationToPassenger.toString(),
|
||||
// rideId.toString(),
|
||||
// rideTimerBegin.toString(),
|
||||
// dataCarsLocationByPassenger['message'][i]['driver_id'].toString(),
|
||||
// durationToRide.toString(),
|
||||
// Get.find<WayPointController>().wayPoints.length > 1
|
||||
// ? 'haveSteps'
|
||||
// : 'startEnd',
|
||||
// placesCoordinate[0],
|
||||
// placesCoordinate[1],
|
||||
// placesCoordinate[2],
|
||||
// placesCoordinate[3],
|
||||
// placesCoordinate[4],
|
||||
// costForDriver.toStringAsFixed(2),
|
||||
// double.parse(box.read(BoxName.passengerWalletTotal)) < 0
|
||||
// ? double.parse(box.read(BoxName.passengerWalletTotal))
|
||||
// .toStringAsFixed(2)
|
||||
// : '0',
|
||||
// box.read(BoxName.email).toString(),
|
||||
// data[0]['start_address'],
|
||||
// data[0]['end_address'],
|
||||
// box.read(BoxName.carType),
|
||||
// kazan.toStringAsFixed(0),
|
||||
// passengerRate.toStringAsFixed(2),
|
||||
// ];
|
||||
// // Log.print('body: ${body}');
|
||||
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'OrderSpeed',
|
||||
rideId.toString(),
|
||||
dataCarsLocationByPassenger['data'][i]['token'].toString(),
|
||||
body,
|
||||
'order.wav');
|
||||
}
|
||||
// FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
// 'OrderSpeed',
|
||||
// rideId.toString(),
|
||||
// dataCarsLocationByPassenger['message'][i]['token'].toString(),
|
||||
// body,
|
||||
// 'order.wav');
|
||||
// }
|
||||
}
|
||||
|
||||
int tick = 0; // Move tick outside the function to maintain its state
|
||||
@@ -1760,6 +1766,7 @@ class MapPassengerController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
String driversStatusForSearchWindow = '';
|
||||
Future<void> confirmRideForAllDriverAvailable() async {
|
||||
bool driversFound = false;
|
||||
const maxAttempts = 8;
|
||||
@@ -1770,7 +1777,7 @@ class MapPassengerController extends GetxController {
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), reloadDuration);
|
||||
// await getNearestDriverByPassengerLocation();
|
||||
|
||||
driversStatusForSearchWindow = 'We are search for nearst driver'.tr;
|
||||
if (isDriversDataValid()) {
|
||||
driversFound = true;
|
||||
break;
|
||||
@@ -1783,9 +1790,16 @@ class MapPassengerController extends GetxController {
|
||||
showNoDriversDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
driversStatusForSearchWindow = 'Your order is being prepared'.tr;
|
||||
Log.print('driversStatusForSearchWindow: ${driversStatusForSearchWindow}');
|
||||
update();
|
||||
await postRideDetailsToServer();
|
||||
driversStatusForSearchWindow = 'Your order sent to drivers'.tr;
|
||||
await notifyAvailableDrivers();
|
||||
|
||||
driversStatusForSearchWindow = 'The drivers are reviewing your request'.tr;
|
||||
Log.print('driversStatusForSearchWindow: ${driversStatusForSearchWindow}');
|
||||
update();
|
||||
delayAndFetchRideStatusForAllDriverAvailable(rideId);
|
||||
update();
|
||||
}
|
||||
@@ -1823,8 +1837,8 @@ class MapPassengerController extends GetxController {
|
||||
bool isDriversDataValid() {
|
||||
return dataCarsLocationByPassenger != 'failure' &&
|
||||
dataCarsLocationByPassenger != null &&
|
||||
dataCarsLocationByPassenger.containsKey('data') &&
|
||||
dataCarsLocationByPassenger['data'] != null;
|
||||
dataCarsLocationByPassenger.containsKey('message') &&
|
||||
dataCarsLocationByPassenger['message'] != null;
|
||||
}
|
||||
|
||||
void showNoDriversDialog() {
|
||||
@@ -1889,7 +1903,8 @@ class MapPassengerController extends GetxController {
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]['driver_id']
|
||||
"driver_id": dataCarsLocationByPassenger['message'][carsOrder]
|
||||
['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
@@ -1911,9 +1926,9 @@ class MapPassengerController extends GetxController {
|
||||
box.read(BoxName.carType), 3000);
|
||||
|
||||
if (dataCarsLocationByPassenger != null &&
|
||||
dataCarsLocationByPassenger.containsKey('data') &&
|
||||
dataCarsLocationByPassenger['data'] != null) {
|
||||
for (var driverData in dataCarsLocationByPassenger['data']) {
|
||||
dataCarsLocationByPassenger.containsKey('message') &&
|
||||
dataCarsLocationByPassenger['message'] != null) {
|
||||
for (var driverData in dataCarsLocationByPassenger['message']) {
|
||||
String driverId = driverData['driver_id'].toString();
|
||||
if (!notifiedDrivers.contains(driverId)) {
|
||||
notifiedDrivers.add(driverId);
|
||||
@@ -1926,14 +1941,18 @@ class MapPassengerController extends GetxController {
|
||||
driverLng,
|
||||
);
|
||||
|
||||
double distanceToDriverInKm = distanceToDriverInMeters / 1000;
|
||||
double distanceToDriverInKm = distanceToDriverInMeters *
|
||||
1.25 / //to approximate to stright distance
|
||||
1000;
|
||||
double durationToDriverInHours =
|
||||
distanceToDriverInKm / 25; // 25 km/h as default speed
|
||||
double durationToDriverInSeconds = durationToDriverInHours * 3600;
|
||||
durationToPassenger = durationToDriverInSeconds.toInt();
|
||||
distanceByPassenger = distanceToDriverInMeters.toStringAsFixed(0);
|
||||
distanceByPassenger =
|
||||
(distanceToDriverInMeters * 1.25).toStringAsFixed(0);
|
||||
Future.delayed(const Duration(microseconds: 10));
|
||||
final body = constructNotificationBody(driverData);
|
||||
Log.print('body:ww ${body}');
|
||||
// Log.print('body:ww ${body}');
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'OrderSpeed',
|
||||
rideId,
|
||||
@@ -1961,8 +1980,8 @@ class MapPassengerController extends GetxController {
|
||||
box.read(BoxName.name).toString(),
|
||||
box.read(BoxName.tokenFCM).toString(),
|
||||
box.read(BoxName.phone).toString(),
|
||||
durationToPassenger.toString(),
|
||||
distanceByPassenger.toString(),
|
||||
durationToPassenger.toStringAsFixed(0) ?? '120',
|
||||
distanceByPassenger.toString() ?? '2000',
|
||||
paymentController.isWalletChecked.toString(),
|
||||
driverData['token'].toString(),
|
||||
durationToPassenger.toString(),
|
||||
@@ -1996,12 +2015,13 @@ class MapPassengerController extends GetxController {
|
||||
StreamController<String>.broadcast();
|
||||
Stream<String> get rideStatusStream => _rideStatusStreamController.stream;
|
||||
|
||||
void delayAndFetchRideStatusForAllDriverAvailable(String rideId) {
|
||||
Future<void> delayAndFetchRideStatusForAllDriverAvailable(
|
||||
String rideId) async {
|
||||
const int maxAttempts = 15;
|
||||
int attemptCounter = 0;
|
||||
bool isApplied = false;
|
||||
tick = 0;
|
||||
|
||||
await addRideToNotificationDriverAvailable();
|
||||
Timer.periodic(const Duration(seconds: 1), (timer) async {
|
||||
if (attemptCounter >= maxAttempts || isApplied) {
|
||||
timer.cancel();
|
||||
@@ -2014,8 +2034,10 @@ class MapPassengerController extends GetxController {
|
||||
|
||||
try {
|
||||
var res = await getRideStatus(rideId);
|
||||
Log.print('res:2022 ${res}');
|
||||
String rideStatusDelayed = res.toString();
|
||||
addRideToNotificationDriverString();
|
||||
Log.print('rideStatusDelayed: ${rideStatusDelayed}');
|
||||
|
||||
_rideStatusStreamController
|
||||
.add(rideStatusDelayed); // Emit the ride status
|
||||
// addRideToNotificationDriverString();
|
||||
@@ -2025,41 +2047,23 @@ class MapPassengerController extends GetxController {
|
||||
"Order Cancelled".tr, "you canceled order".tr, 'ding');
|
||||
_rideStatusStreamController
|
||||
.close(); // Close stream after cancellation
|
||||
//
|
||||
//
|
||||
} else if (rideStatusDelayed == 'Apply' ||
|
||||
rideStatusDelayed == 'Applied') {
|
||||
await getUpdatedRideForDriverApply(rideId);
|
||||
NotificationController().showNotification(
|
||||
'Order Accepted'.tr,
|
||||
'$driverName ${'accepted your order at price'.tr} ${totalPassenger.toStringAsFixed(1)} ${'with type'.tr} ${box.read(BoxName.carType)}',
|
||||
'ding');
|
||||
if (box.read(BoxName.carType) == 'Speed' ||
|
||||
box.read(BoxName.carType) == 'Awfar Car') {
|
||||
NotificationController().showNotification(
|
||||
'The captain is responsible for the route.'.tr,
|
||||
'This price is fixed even if the route changes for the driver.'
|
||||
.tr,
|
||||
'ding');
|
||||
} else if (box.read(BoxName.carType) == 'Comfort' ||
|
||||
box.read(BoxName.carType) == 'Lady') {
|
||||
NotificationController().showNotification('Attention'.tr,
|
||||
'The price may increase if the route changes.'.tr, 'ding');
|
||||
}
|
||||
isApplied = true;
|
||||
statusRide = 'Apply';
|
||||
rideConfirm = false;
|
||||
isSearchingWindow = false;
|
||||
|
||||
startTimer();
|
||||
update();
|
||||
startTimerFromDriverToPassengerAfterApplied();
|
||||
|
||||
rideAppliedFromDriver(isApplied);
|
||||
timer.cancel();
|
||||
_rideStatusStreamController.close(); // Close stream after applying
|
||||
} else if (attemptCounter >= maxAttempts &&
|
||||
// Close stream after applying
|
||||
} else if (attemptCounter >= maxAttempts ||
|
||||
rideStatusDelayed != 'Cancel') {
|
||||
timer.cancel();
|
||||
timer.cancel(); //todo
|
||||
// addRideToNotificationDriverString();
|
||||
// Show dialog to increase fee...
|
||||
MyDialog().getDialog(
|
||||
'Are you want to wait drivers to accept your order'.tr, '', () {
|
||||
Get.back();
|
||||
addRideToNotificationDriverAvailable();
|
||||
});
|
||||
update();
|
||||
_rideStatusStreamController
|
||||
.close(); // Close stream after max attempts
|
||||
@@ -2070,6 +2074,36 @@ class MapPassengerController extends GetxController {
|
||||
});
|
||||
}
|
||||
|
||||
rideAppliedFromDriver(bool isApplied) async {
|
||||
await getUpdatedRideForDriverApply(rideId);
|
||||
NotificationController().showNotification(
|
||||
'Order Accepted'.tr,
|
||||
'$driverName ${'accepted your order at price'.tr} ${totalPassenger.toStringAsFixed(1)} ${'with type'.tr} ${box.read(BoxName.carType)}',
|
||||
'ding');
|
||||
if (box.read(BoxName.carType) == 'Speed' ||
|
||||
box.read(BoxName.carType) == 'Awfar Car') {
|
||||
NotificationController().showNotification(
|
||||
'The captain is responsible for the route.'.tr,
|
||||
'This price is fixed even if the route changes for the driver.'.tr,
|
||||
'ding');
|
||||
} else if (box.read(BoxName.carType) == 'Comfort' ||
|
||||
box.read(BoxName.carType) == 'Lady') {
|
||||
NotificationController().showNotification('Attention'.tr,
|
||||
'The price may increase if the route changes.'.tr, 'ding');
|
||||
}
|
||||
isApplied = true;
|
||||
statusRide = 'Apply';
|
||||
rideConfirm = false;
|
||||
isSearchingWindow = false;
|
||||
update();
|
||||
startTimer();
|
||||
// todo stop this because this method in startTimer()
|
||||
// startTimerFromDriverToPassengerAfterApplied();
|
||||
|
||||
// timer.cancel();
|
||||
_rideStatusStreamController.close();
|
||||
}
|
||||
|
||||
// Listening to the Stream
|
||||
void listenToRideStatusStream() {
|
||||
rideStatusStream.listen((rideStatus) {
|
||||
@@ -2084,15 +2118,12 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
|
||||
reSearchAfterCanceledFromDriver() async {
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 3000);
|
||||
|
||||
updateConfirmRideForAllDriverAvailable();
|
||||
shouldFetch = true; // Stop further fetches
|
||||
statusRide = 'wait';
|
||||
rideConfirm = true;
|
||||
isSearchingWindow = true;
|
||||
update();
|
||||
updateConfirmRideForAllDriverAvailable();
|
||||
}
|
||||
|
||||
void start15SecondTimer(String rideId) {
|
||||
@@ -2131,7 +2162,8 @@ class MapPassengerController extends GetxController {
|
||||
final response = await CRUD().get(
|
||||
link: "${AppLink.endPoint}/ride/rides/getRideStatus.php",
|
||||
payload: {'id': rideId});
|
||||
|
||||
print(response);
|
||||
print('2140');
|
||||
return jsonDecode(response)['data'];
|
||||
}
|
||||
|
||||
@@ -2492,11 +2524,12 @@ class MapPassengerController extends GetxController {
|
||||
} else {
|
||||
noCarString = false;
|
||||
dataCarsLocationByPassenger = jsonDecode(res);
|
||||
Log.print('dataCarsLocationByPassenger: ${dataCarsLocationByPassenger}');
|
||||
Log.print(
|
||||
'dataCarsLocationByPassenger:getCarsLocationByPassengerAndReloadMarker ${dataCarsLocationByPassenger}');
|
||||
|
||||
// Check if 'message' is present and not null
|
||||
if (dataCarsLocationByPassenger['data'] != null &&
|
||||
dataCarsLocationByPassenger['data'].isNotEmpty) {
|
||||
if (dataCarsLocationByPassenger != null &&
|
||||
dataCarsLocationByPassenger.isNotEmpty) {
|
||||
// Check if carsOrder is within bounds
|
||||
// if (carsOrder < dataCarsLocationByPassenger['message'].length) {
|
||||
// driverId = dataCarsLocationByPassenger['message'][carsOrder]
|
||||
@@ -2508,7 +2541,7 @@ class MapPassengerController extends GetxController {
|
||||
// ['token']
|
||||
// .toString();
|
||||
// } else {
|
||||
// print('carsOrder is out of bounds for message array');
|
||||
print('carsOrder is in of bounds for message array');
|
||||
// return false;
|
||||
// }
|
||||
} else {
|
||||
@@ -2519,8 +2552,8 @@ class MapPassengerController extends GetxController {
|
||||
|
||||
carsLocationByPassenger.clear(); // Clear existing markers
|
||||
|
||||
for (var i = 0; i < dataCarsLocationByPassenger['data'].length; i++) {
|
||||
var json = dataCarsLocationByPassenger['data'][i];
|
||||
for (var i = 0; i < dataCarsLocationByPassenger['message'].length; i++) {
|
||||
var json = dataCarsLocationByPassenger['message'][i];
|
||||
_updateOrCreateMarker(
|
||||
MarkerId(json['latitude']).toString(),
|
||||
LatLng(
|
||||
@@ -3778,13 +3811,15 @@ class MapPassengerController extends GetxController {
|
||||
if (!rideConfirm) {
|
||||
if (dataCarsLocationByPassenger != 'failure' &&
|
||||
dataCarsLocationByPassenger != null &&
|
||||
dataCarsLocationByPassenger['data'] != null &&
|
||||
dataCarsLocationByPassenger['data'].length > 0) {
|
||||
dataCarsLocationByPassenger['message'] != null &&
|
||||
dataCarsLocationByPassenger['message'].length > 0) {
|
||||
double nearestDistance = double.infinity; // Initialize nearest distance
|
||||
CarLocation? nearestCar;
|
||||
|
||||
for (var i = 0; i < dataCarsLocationByPassenger['data'].length; i++) {
|
||||
var carLocation = dataCarsLocationByPassenger['data'][i];
|
||||
for (var i = 0;
|
||||
i < dataCarsLocationByPassenger['message'].length;
|
||||
i++) {
|
||||
var carLocation = dataCarsLocationByPassenger['message'][i];
|
||||
Log.print('carLocation: $carLocation');
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user