This commit is contained in:
Hamza-Ayed
2025-07-01 18:30:08 +03:00
parent cf8966ea29
commit 322e4b9788
11 changed files with 1445 additions and 74 deletions

View File

@@ -35,6 +35,7 @@ import '../../models/model/painter_copoun.dart';
import '../../print.dart';
import '../../views/home/map_widget.dart/cancel_raide_page.dart';
import '../../views/home/map_widget.dart/car_details_widget_to_go.dart';
import '../../views/home/map_widget.dart/searching_captain_window.dart';
import '../../views/home/map_widget.dart/select_driver_mishwari.dart';
import '../../views/widgets/elevated_btn.dart';
import '../../views/widgets/error_snakbar.dart';
@@ -79,7 +80,10 @@ class MapPassengerController extends GetxController {
List wayPoint2 = [];
List wayPoint3 = [];
List wayPoint4 = [];
final firebaseMessagesController =
Get.isRegistered<FirebaseMessagesController>()
? Get.find<FirebaseMessagesController>()
: Get.put(FirebaseMessagesController());
List<List<dynamic>> placeListResponseAll = [];
List<Widget> placeListResponse = [
@@ -367,6 +371,8 @@ class MapPassengerController extends GetxController {
totalPassenger = double.parse(increasFeeFromPassenger.text);
Get.back();
if (rideId != 'yet') {
Log.print('rideId from increase: ${rideId}');
notifyAvailableDriversAgain();
await CRUD().post(link: AppLink.updateDriverOrder, payload: {
"order_id": rideId.toString(), // Convert to String
"status": 'waiting'
@@ -943,7 +949,7 @@ class MapPassengerController extends GetxController {
box.write(BoxName.passengerWalletTotal, '0');
update();
if (box.read(BoxName.parentTripSelected) == true) {
Get.find<FirebaseMessagesController>().sendNotificationToPassengerToken(
firebaseMessagesController.sendNotificationToPassengerToken(
"Finish Monitor".tr,
"Finish Monitor".tr,
box.read(BoxName.tokenParent),
@@ -1531,7 +1537,7 @@ class MapPassengerController extends GetxController {
// passengerRate.toStringAsFixed(2),
// ];
// Log.print('body: ${body}');
// Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
// firebaseMessagesController.sendNotificationToDriverMAP(
// 'OrderSpeed',
// rideId,
// driverData['token'].toString(),
@@ -1674,7 +1680,7 @@ class MapPassengerController extends GetxController {
// ];
// // Log.print('body: ${body}');
// Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
// firebaseMessagesController.sendNotificationToDriverMAP(
// 'OrderSpeed',
// rideId.toString(),
// dataCarsLocationByPassenger['message'][i]['token'].toString(),
@@ -1957,8 +1963,8 @@ class MapPassengerController extends GetxController {
Future.delayed(const Duration(microseconds: 10));
final body = constructNotificationBody(driverData);
Log.print('body:ww ${body}');
Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
'Order'.tr,
firebaseMessagesController.sendNotificationToDriverMAP(
'Order', // without tr since background not valid
endNameAddress,
(driverData['token'].toString()),
body,
@@ -1970,6 +1976,53 @@ class MapPassengerController extends GetxController {
}
}
Future<void> notifyAvailableDriversAgain() async {
Log.print('[DEBUG] Starting notifyAvailableDriversAgain()');
await getCarsLocationByPassengerAndReloadMarker(
box.read(BoxName.carType), 3000);
Log.print(
'[DEBUG] Found drivers to notify: ${dataCarsLocationByPassenger['message']?.length}');
if (dataCarsLocationByPassenger != null &&
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);
double driverLat = double.parse(driverData['latitude']);
double driverLng = double.parse(driverData['longitude']);
double distanceToDriverInMeters = Geolocator.distanceBetween(
passengerLocation.latitude,
passengerLocation.longitude,
driverLat,
driverLng,
);
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 * 1.25).toStringAsFixed(0);
Future.delayed(const Duration(microseconds: 10));
final body = constructNotificationBody(driverData);
// Log.print('body:ww ${body}');
Log.print(
'[DEBUG] Sending to driver: ${driverData['driver_id']}, token: ${driverData['token']}');
firebaseMessagesController.sendNotificationToDriverMAP(
'Order', // without tr since background not valid
endNameAddress,
(driverData['token'].toString()),
body,
'order.wav');
}
}
}
}
List<String> constructNotificationBody(var driverData) {
final paymentController = Get.find<PaymentController>();
return [
@@ -2019,7 +2072,7 @@ class MapPassengerController extends GetxController {
StreamController<String>.broadcast();
Stream<String> get rideStatusStream => _rideStatusStreamController.stream;
int maxAttempts = 15;
int maxAttempts = 28;
Future<void> delayAndFetchRideStatusForAllDriverAvailable(
String rideId) async {
@@ -2039,7 +2092,6 @@ class MapPassengerController extends GetxController {
try {
var res = await getRideStatus(rideId);
Log.print('res:2047 $res');
String rideStatusDelayed = res.toString();
Log.print('rideStatusDelayed: $rideStatusDelayed');
@@ -2061,15 +2113,33 @@ class MapPassengerController extends GetxController {
timer.cancel();
// Close stream after applying
} else if (attemptCounter >= maxAttempts ||
rideStatusDelayed != 'Cancel') {
timer.cancel(); //todo
rideStatusDelayed == 'waiting') {
// 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();
});
// buildTimerForIncrease();
Get.defaultDialog(
title: 'Are you want to wait drivers to accept your order'.tr,
middleText: '',
onConfirm: () {
Log.print('[DEBUG] User chose to wait again');
Get.back();
notifyAvailableDriversAgain();
delayAndFetchRideStatusForAllDriverAvailable(rideId);
// addRideToNotificationDriverAvailable();
},
onCancel: () {
timer.cancel();
Get.back();
showCancelRideBottomSheet();
},
);
// MyDialog().getDialog(
// 'Are you want to wait drivers to accept your order'.tr, '', () {
// Get.back();
// addRideToNotificationDriverAvailable();
// });
update();
_rideStatusStreamController
.close(); // Close stream after max attempts
@@ -2083,7 +2153,7 @@ class MapPassengerController extends GetxController {
rideAppliedFromDriver(bool isApplied) async {
await getUpdatedRideForDriverApply(rideId);
NotificationController().showNotification(
'Order Accepted'.tr,
'Accepted Ride'.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' ||
@@ -2202,7 +2272,7 @@ class MapPassengerController extends GetxController {
}
// driversToken.remove(driverToken);
// for (var i = 1; i < driversToken.length; i++) {
Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
firebaseMessagesController.sendNotificationToDriverMAP(
'Order Accepted'.tr,
'$driverName${'Accepted your order'.tr}',
driverToken.toString(),
@@ -2920,7 +2990,7 @@ class MapPassengerController extends GetxController {
var tokenParent = (res1['data'][0]['token']);
Get.snackbar("The invitation was sent successfully".tr, '',
backgroundColor: AppColor.greenColor);
Get.find<FirebaseMessagesController>().sendNotificationToPassengerToken(
firebaseMessagesController.sendNotificationToPassengerToken(
"Trip Monitoring".tr,
"Trip Monitoring".tr,
tokenParent,
@@ -3157,7 +3227,7 @@ class MapPassengerController extends GetxController {
changeCancelRidePageShow();
if (rideId != 'yet') {
Log.print('cancelRide: 1');
await Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
await firebaseMessagesController.sendNotificationToDriverMAP(
'Cancel Trip'.tr,
'Trip Cancelled'.tr,
driverToken.toString(),
@@ -5164,33 +5234,32 @@ class MapPassengerController extends GetxController {
timeSelected);
// Optionally, set up local notification or send a push notification
await Get.find<FirebaseMessagesController>()
.sendNotificationToDriverMAP(
'OrderVIP',
rideId.toString(),
(driver['token'].toString()),
[
id,
rideId,
driver['id'],
passengerLocation.latitude.toString(),
startNameAddress.toString(),
passengerLocation.longitude.toString(),
(box.read(BoxName.name).toString().split(' ')[0]).toString(),
box.read(BoxName.passengerID).toString(),
box.read(BoxName.phone).toString(),
box.read(BoxName.email).toString(),
box.read(BoxName.passengerPhotoUrl).toString(),
box.read(BoxName.tokenFCM).toString(),
(driver['token'].toString()),
],
'order.wav');
await firebaseMessagesController.sendNotificationToDriverMAP(
'OrderVIP',
rideId.toString(),
(driver['token'].toString()),
[
id,
rideId,
driver['id'],
passengerLocation.latitude.toString(),
startNameAddress.toString(),
passengerLocation.longitude.toString(),
(box.read(BoxName.name).toString().split(' ')[0]).toString(),
box.read(BoxName.passengerID).toString(),
box.read(BoxName.phone).toString(),
box.read(BoxName.email).toString(),
box.read(BoxName.passengerPhotoUrl).toString(),
box.read(BoxName.tokenFCM).toString(),
(driver['token'].toString()),
],
'order.wav');
if (response['message'] == "Trip updated successfully") {
mySnackbarSuccess("Trip updated successfully".tr);
Log.print(
'previous_driver_token: ${response['previous_driver_token']}');
Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
firebaseMessagesController.sendNotificationToDriverMAP(
'Order VIP Canceld'.tr,
'Passenger cancel order'.tr,
response['previous_driver_token'].toString(),
@@ -5214,7 +5283,7 @@ class MapPassengerController extends GetxController {
}
cancelVip(String token, tripId) async {
// Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
// firebaseMessagesController.sendNotificationToDriverMAP(
// 'Order VIP Canceld'.tr,
// 'Passenger cancel order'.tr,
// token,
@@ -5230,7 +5299,7 @@ class MapPassengerController extends GetxController {
}
sendToDriverAgain(String token) {
Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
firebaseMessagesController.sendNotificationToDriverMAP(
'Order VIP Canceld'.tr,
'Passenger cancel order'.tr,
token,