11/9/1
This commit is contained in:
@@ -769,7 +769,8 @@ class MapPassengerController extends GetxController {
|
||||
if (res != 'failure') {
|
||||
var decode = jsonDecode(res);
|
||||
|
||||
if (decode['data']['status'] != 'Apply') {
|
||||
// if (decode['data']['status'] != 'Apply') {
|
||||
if (decode['data']['status'] == 'Begin') {
|
||||
timeToPassengerFromDriverAfterApplied = 0;
|
||||
remainingTime = 0;
|
||||
remainingTimeToPassengerFromDriverAfterApplied = 0;
|
||||
@@ -1077,7 +1078,7 @@ class MapPassengerController extends GetxController {
|
||||
// licensePlate = nearestDriverData['car_plate'].toString();
|
||||
// startCarLocationSearch(box.read(BoxName.carType));
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 4500);
|
||||
box.read(BoxName.carType), 3000);
|
||||
// await getCarsLocationByPassengerAndReloadMarker(
|
||||
// box.read(BoxName.carType), 7000);
|
||||
// await getNearestDriverByPassengerLocation();
|
||||
@@ -1112,26 +1113,28 @@ class MapPassengerController extends GetxController {
|
||||
isDriversTokensSend = false;
|
||||
|
||||
update();
|
||||
await CRUD()
|
||||
.post(link: "${AppLink.endPoint}/ride/rides/add.php", payload: {
|
||||
"start_location": //'${data[0]['start_address']}',
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location": //'${data[0]['end_address']}',
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
"date": DateTime.now().toString(),
|
||||
"time": DateTime.now().toString(),
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
}).then((value) {
|
||||
await CRUD().post(
|
||||
link: "${AppLink.seferCairoServer}/ride/rides/add.php",
|
||||
payload: {
|
||||
"start_location": //'${data[0]['start_address']}',
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location": //'${data[0]['end_address']}',
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
"date": DateTime.now().toString(),
|
||||
"time": DateTime.now().toString(),
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]
|
||||
['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
}).then((value) {
|
||||
// List<String> body = [
|
||||
rideId = jsonDecode(value)['message'];
|
||||
List<String> body = [
|
||||
@@ -1188,6 +1191,29 @@ class MapPassengerController extends GetxController {
|
||||
Log.print(
|
||||
'dataCarsLocationByPassenger[data]: ${dataCarsLocationByPassenger['data'][carsOrder]['token']}');
|
||||
});
|
||||
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(link: "${AppLink.endPoint}/ride/rides/add.php", payload: {
|
||||
"start_location": //'${data[0]['start_address']}',
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location": //'${data[0]['end_address']}',
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
"date": DateTime.now().toString(),
|
||||
"time": DateTime.now().toString(),
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]
|
||||
['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
});
|
||||
}
|
||||
delayAndFetchRideStatus(rideId, box.read(BoxName.carType));
|
||||
if (shouldFetch == false) {
|
||||
startTimer();
|
||||
@@ -1211,10 +1237,11 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
String driverOrderStatus = 'yet';
|
||||
bool isDriversTokensSend = false;
|
||||
confirmRideForAllDriverAvailable() async {
|
||||
confirmRideForAllDriverAvailable0() async {
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 4500);
|
||||
box.read(BoxName.carType), 3500);
|
||||
if (dataCarsLocationByPassenger != 'failure') {
|
||||
// driversToken.remove(driverToken);
|
||||
PaymentController paymentController = Get.find<PaymentController>();
|
||||
@@ -1291,33 +1318,38 @@ class MapPassengerController extends GetxController {
|
||||
// Log.print('body: ${body}');
|
||||
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'OrderSpeed',
|
||||
rideId.toString(),
|
||||
dataCarsLocationByPassenger['data'][i]['token'].toString(),
|
||||
body,
|
||||
'order.wav');
|
||||
'OrderSpeed',
|
||||
rideId.toString(),
|
||||
dataCarsLocationByPassenger['data'][i]['token'].toString(),
|
||||
body,
|
||||
'order.wav',
|
||||
);
|
||||
driverOrderStatus = 'recive';
|
||||
}
|
||||
});
|
||||
(rideId); //
|
||||
CRUD().post(link: '${AppLink.endPoint}/ride/rides/add.php', payload: {
|
||||
"start_location": //'${data[0]['start_address']}',
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location": //'${data[0]['end_address']}',
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
"date": DateTime.now().toString(),
|
||||
"time": DateTime.now().toString(),
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
});
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(link: '${AppLink.endPoint}/ride/rides/add.php', payload: {
|
||||
"start_location": //'${data[0]['start_address']}',
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location": //'${data[0]['end_address']}',
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
"date": DateTime.now().toString(),
|
||||
"time": DateTime.now().toString(),
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]
|
||||
['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
delayAndFetchRideStatusForAllDriverAvailable(rideId);
|
||||
update();
|
||||
@@ -1330,6 +1362,344 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> notifiedDrivers = {};
|
||||
|
||||
confirmRideForAllDriverAvailable() async {
|
||||
// Fetch car locations
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 3000);
|
||||
|
||||
// Ensure dataCarsLocationByPassenger is not 'failure' or null
|
||||
if (dataCarsLocationByPassenger != 'failure' &&
|
||||
dataCarsLocationByPassenger != null) {
|
||||
// Check if 'data' key exists and is not null
|
||||
if (dataCarsLocationByPassenger.containsKey('data') &&
|
||||
dataCarsLocationByPassenger['data'] != null) {
|
||||
PaymentController paymentController = Get.find<PaymentController>();
|
||||
rideConfirm = true;
|
||||
shouldFetch = true;
|
||||
isBottomSheetShown = false;
|
||||
timeToPassengerFromDriverAfterApplied = 60;
|
||||
|
||||
// Add ride to database
|
||||
await CRUD().post(
|
||||
link: "${AppLink.seferCairoServer}/ride/rides/add.php",
|
||||
payload: {
|
||||
"start_location":
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location":
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
"date": DateTime.now().toString(),
|
||||
"time": DateTime.now().toString(),
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]
|
||||
['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
}).then((value) {
|
||||
if (value is String) {
|
||||
final parsedValue = jsonDecode(value);
|
||||
rideId = parsedValue['message'];
|
||||
} else if (value is Map) {
|
||||
rideId = value['message'];
|
||||
} else {
|
||||
Log.print('Unexpected response type: ${value.runtimeType}');
|
||||
}
|
||||
// Log.print('value: ${value}');
|
||||
// rideId = jsonDecode(value)['message'];
|
||||
// rideId = jsonDecode(value)['message'].toString();
|
||||
|
||||
// Timer for 5 iterations, runs every 2 seconds
|
||||
int iteration = 0;
|
||||
Timer.periodic(const Duration(seconds: 2), (timer) async {
|
||||
if (iteration >= 5) {
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
iteration++;
|
||||
|
||||
// Reload driver locations
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 3000);
|
||||
|
||||
// Ensure dataCarsLocationByPassenger and data key are still valid
|
||||
if (dataCarsLocationByPassenger != null &&
|
||||
dataCarsLocationByPassenger.containsKey('data') &&
|
||||
dataCarsLocationByPassenger['data'] != null) {
|
||||
// Notify only new drivers
|
||||
for (var driverData in dataCarsLocationByPassenger['data']) {
|
||||
String driverId = driverData['driver_id'].toString();
|
||||
if (!notifiedDrivers.contains(driverId)) {
|
||||
notifiedDrivers.add(driverId);
|
||||
|
||||
// Prepare body payload for notification
|
||||
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),
|
||||
driverId,
|
||||
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(),
|
||||
driverData['token'].toString(),
|
||||
durationToPassenger.toString(),
|
||||
rideId,
|
||||
rideTimerBegin.toString(),
|
||||
driverId,
|
||||
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),
|
||||
];
|
||||
|
||||
// Send notification to the driver
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'OrderSpeed',
|
||||
rideId,
|
||||
driverData['token'].toString(),
|
||||
body,
|
||||
'order.wav',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Check for additional server endpoint
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(link: '${AppLink.endPoint}/ride/rides/add.php', payload: {
|
||||
"start_location":
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location":
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
"date": DateTime.now().toString(),
|
||||
"time": DateTime.now().toString(),
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]
|
||||
['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
});
|
||||
}
|
||||
delayAndFetchRideStatusForAllDriverAvailable(rideId);
|
||||
update();
|
||||
} else {
|
||||
// Show dialog if no drivers found in data key
|
||||
MyDialog().getDialog("No Car or Driver Found in your area.".tr,
|
||||
"No Car or Driver Found in your area.".tr, () {
|
||||
Get.back();
|
||||
Get.offAll(const MapPagePassenger());
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Show dialog if dataCarsLocationByPassenger is 'failure' or null
|
||||
MyDialog().getDialog("No Car or Driver Found in your area.".tr,
|
||||
"No Car or Driver Found in your area.".tr, () {
|
||||
Get.back();
|
||||
Get.offAll(const MapPagePassenger());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
confirmRideForAllDriverAvailable1() async {
|
||||
int attempts = 0;
|
||||
const int maxAttempts = 4;
|
||||
const Duration delayDuration = Duration(seconds: 2);
|
||||
|
||||
// Initial data fetch
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 3000);
|
||||
|
||||
if (dataCarsLocationByPassenger != null &&
|
||||
dataCarsLocationByPassenger != 'failure') {
|
||||
PaymentController paymentController = Get.find<PaymentController>();
|
||||
rideConfirm = true;
|
||||
shouldFetch = true;
|
||||
isBottomSheetShown = false;
|
||||
timeToPassengerFromDriverAfterApplied = 60;
|
||||
|
||||
// Create a set to keep track of notified driver IDs
|
||||
Set<String> notifiedDriverIds = {};
|
||||
|
||||
// Send the initial ride request once
|
||||
rideId = await CRUD().post(
|
||||
link: "${AppLink.seferCairoServer}/ride/rides/add.php",
|
||||
payload: {
|
||||
"start_location":
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location":
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
"date": DateTime.now().toString(),
|
||||
"time": DateTime.now().toString(),
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]
|
||||
['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
}).then((value) => jsonDecode(value)['message']);
|
||||
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(link: '${AppLink.endPoint}/ride/rides/add.php', payload: {
|
||||
"start_location": //'${data[0]['start_address']}',
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
"end_location": //'${data[0]['end_address']}',
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
"date": DateTime.now().toString(),
|
||||
"time": DateTime.now().toString(),
|
||||
"endtime": durationToAdd.toString(),
|
||||
"price": totalPassenger.toStringAsFixed(2),
|
||||
"passenger_id": box.read(BoxName.passengerID).toString(),
|
||||
"driver_id": dataCarsLocationByPassenger['data'][carsOrder]
|
||||
['driver_id']
|
||||
.toString(),
|
||||
"status": "waiting",
|
||||
'carType': box.read(BoxName.carType),
|
||||
"price_for_driver": totalPassenger.toString(),
|
||||
"price_for_passenger": totalME.toString(),
|
||||
"distance": distance.toString(),
|
||||
"paymentMethod": paymentController.isWalletChecked.toString(),
|
||||
});
|
||||
}
|
||||
// Add the initially available drivers to the notified set
|
||||
for (var driver in dataCarsLocationByPassenger['data']) {
|
||||
notifiedDriverIds.add(driver['driver_id'].toString());
|
||||
}
|
||||
|
||||
// Periodically check for new drivers
|
||||
Timer.periodic(delayDuration, (Timer timer) async {
|
||||
attempts++;
|
||||
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 3000);
|
||||
|
||||
if (dataCarsLocationByPassenger != 'failure') {
|
||||
// Check for new drivers and notify them
|
||||
for (var driver in dataCarsLocationByPassenger['data']) {
|
||||
String driverId = driver['driver_id'].toString();
|
||||
|
||||
// Only notify new drivers
|
||||
if (!notifiedDriverIds.contains(driverId)) {
|
||||
notifiedDriverIds.add(driverId);
|
||||
|
||||
// Prepare notification body
|
||||
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),
|
||||
driverId,
|
||||
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(),
|
||||
driver['token'].toString(),
|
||||
durationToPassenger.toString(),
|
||||
rideId,
|
||||
rideTimerBegin.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),
|
||||
];
|
||||
|
||||
// Send notification to the new driver
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'OrderSpeed',
|
||||
rideId.toString(),
|
||||
driver['token'].toString(),
|
||||
body,
|
||||
'order.wav',
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MyDialog().getDialog("No Car or Driver Found in your area.".tr,
|
||||
"No Car or Driver Found in your area.".tr, () {
|
||||
Get.back();
|
||||
Get.offAll(const MapPagePassenger());
|
||||
});
|
||||
}
|
||||
|
||||
// Stop after max attempts
|
||||
if (attempts >= maxAttempts) {
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
MyDialog().getDialog("No Car or Driver Found in your area.".tr,
|
||||
"No Car or Driver Found in your area.".tr, () {
|
||||
Get.back();
|
||||
Get.offAll(const MapPagePassenger());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
icreaseForSameRideAndDelay() {
|
||||
PaymentController paymentController = Get.find<PaymentController>();
|
||||
rideConfirm = true;
|
||||
@@ -1398,19 +1768,20 @@ class MapPassengerController extends GetxController {
|
||||
String res = await getRideStatus(rideId);
|
||||
|
||||
Log.print('tick: $tick');
|
||||
|
||||
if ((res.toString() == 'waiting' || res.toString() == 'Refused') &&
|
||||
String rideStatusDelayed = res.toString();
|
||||
if ((rideStatusDelayed == 'waiting' ||
|
||||
rideStatusDelayed == 'Refused') &&
|
||||
tick >= 15) {
|
||||
timer.cancel(); // Stop the current timer
|
||||
showAndResearchForCaptain();
|
||||
//TODO add to wait
|
||||
await getCarsLocationByPassengerAndReloadMarker(carType, 4500);
|
||||
await getCarsLocationByPassengerAndReloadMarker(carType, 3000);
|
||||
// await getNearestDriverByPassengerLocationAPIGOOGLE();
|
||||
// getCarForFirstConfirm(carType);
|
||||
confirmRideForAllDriverAvailable();
|
||||
// delayAndFetchRideStatusForAllDriverAvailable(rideId);
|
||||
} else if (res.toString() == 'Apply') {
|
||||
Log.print('res.toString() == Apply: ${res.toString()}');
|
||||
} else if (rideStatusDelayed == 'Apply') {
|
||||
Log.print('rideStatusDelayed == Apply: ${rideStatusDelayed}');
|
||||
// todo play sound
|
||||
Get.find<AudioRecorderController>()
|
||||
.playSoundFromAssets('assets/start.wav');
|
||||
@@ -1422,7 +1793,7 @@ class MapPassengerController extends GetxController {
|
||||
isSearchingWindow = false;
|
||||
update();
|
||||
startTimerFromDriverToPassengerAfterApplied();
|
||||
} else if (res.toString() == 'Refused') {
|
||||
} else if (rideStatusDelayed == 'Refused') {
|
||||
statusRide = 'Refused';
|
||||
if (isDriversTokensSend == false) {
|
||||
confirmRideForAllDriverAvailable();
|
||||
@@ -1473,17 +1844,22 @@ class MapPassengerController extends GetxController {
|
||||
attemptCounter++;
|
||||
tick++;
|
||||
var res = await getRideStatus(rideId);
|
||||
String rideStatusDelayed = res.toString();
|
||||
|
||||
if (res.toString() == 'Apply' || res.toString() == 'Applied') {
|
||||
if (rideStatusDelayed == 'Apply' || rideStatusDelayed == 'Applied') {
|
||||
await getUpdatedRideForDriverApply(rideId);
|
||||
isApplied = true;
|
||||
shouldFetch = false;
|
||||
statusRide = 'Apply';
|
||||
rideConfirm = false;
|
||||
isSearchingWindow = false;
|
||||
|
||||
startTimer();
|
||||
|
||||
update();
|
||||
startTimerFromDriverToPassengerAfterApplied();
|
||||
} else if (attemptCounter >= maxAttempts && statusRide != 'Cancel') {
|
||||
} else if (attemptCounter >= maxAttempts &&
|
||||
rideStatusDelayed != 'Cancel') {
|
||||
shouldFetch = false;
|
||||
// If the status is still not "Apply" after 15 attempts
|
||||
MyDialog().getDialog('upgrade price'.tr,
|
||||
@@ -1573,7 +1949,7 @@ class MapPassengerController extends GetxController {
|
||||
|
||||
reSearchAfterCanceledFromDriver() async {
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 4500);
|
||||
box.read(BoxName.carType), 3000);
|
||||
|
||||
confirmRideForAllDriverAvailable();
|
||||
shouldFetch = true; // Stop further fetches
|
||||
@@ -1616,8 +1992,9 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
|
||||
Future<String> getRideStatus(String rideId) async {
|
||||
final response =
|
||||
await CRUD().get(link: AppLink.getRideStatus, payload: {'id': rideId});
|
||||
final response = await CRUD().get(
|
||||
link: "${AppLink.endPoint}/ride/rides/getRideStatus.php",
|
||||
payload: {'id': rideId});
|
||||
|
||||
return jsonDecode(response)['data'];
|
||||
}
|
||||
@@ -1638,7 +2015,7 @@ class MapPassengerController extends GetxController {
|
||||
make = response['data']['make'];
|
||||
licensePlate = response['data']['car_plate'];
|
||||
firstName = response['data']['first_name'];
|
||||
driverName = response['data']['driverName'];
|
||||
driverName = response['data']['driverName'].toString().split(' ')[0];
|
||||
driverToken = response['data']['token'];
|
||||
Log.print('driverToken updated: $driverToken');
|
||||
carYear = response['data']['year'];
|
||||
@@ -1646,10 +2023,11 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
// driversToken.remove(driverToken);
|
||||
// for (var i = 1; i < driversToken.length; i++) {
|
||||
FirebaseMessagesController().sendNotificationToAnyWithoutData(
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Order Applied'.tr,
|
||||
'$driverName Apply order\nTake attention in other order'.tr,
|
||||
driverToken,
|
||||
[],
|
||||
'start.wav',
|
||||
);
|
||||
// }
|
||||
@@ -1871,6 +2249,7 @@ class MapPassengerController extends GetxController {
|
||||
longitude >= 31.215009 &&
|
||||
longitude <= 31.532186) {
|
||||
box.write(BoxName.serverChosen, AppLink.seferCairoServer);
|
||||
|
||||
return 'Cairo';
|
||||
} else if (latitude >= 29.904975 &&
|
||||
latitude <= 30.143372 &&
|
||||
@@ -2380,12 +2759,13 @@ class MapPassengerController extends GetxController {
|
||||
double tripDurationInMinutes = durationToRide / 6;
|
||||
int loopCount = tripDurationInMinutes.ceil();
|
||||
// If the trip duration is less than or equal to 50 minutes, then break the loop.
|
||||
clearMarkersExceptStartEnd();
|
||||
for (var i = 0; i < loopCount; i++) {
|
||||
// Wait for 50 seconds.
|
||||
await Future.delayed(const Duration(seconds: 4));
|
||||
if (rideTimerBegin == true && statusRide == 'Apply') {
|
||||
await getDriverCarsLocationToPassengerAfterApplied();
|
||||
}
|
||||
// if (rideTimerBegin == true && statusRide == 'Apply') {
|
||||
await getDriverCarsLocationToPassengerAfterApplied();
|
||||
// }
|
||||
reloadMarkerDriverCarsLocationToPassengerAfterApplied();
|
||||
}
|
||||
}
|
||||
@@ -2517,79 +2897,66 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
|
||||
Future cancelRide() async {
|
||||
if (rideConfirm == false && statusRide == 'Apply' ||
|
||||
statusRide == 'Applied' ||
|
||||
statusRide == 'waiting') {
|
||||
clearPlacesDestination();
|
||||
clearPolyline();
|
||||
// clearPolylineAll();
|
||||
data = [];
|
||||
changeCancelRidePageShow();
|
||||
if (rideId != 'yet') {
|
||||
await CRUD().post(link: AppLink.updateDriverOrder, payload: {
|
||||
"order_id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
});
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Cancel Trip',
|
||||
'Trip Cancelled'.tr,
|
||||
driverToken,
|
||||
[],
|
||||
'cancel.wav',
|
||||
);
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(
|
||||
link: "$AppLink.endPoint/ride/driver_order/update.php",
|
||||
payload: {
|
||||
"order_id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
});
|
||||
}
|
||||
await CRUD().post(link: AppLink.updateRides, payload: {
|
||||
// if (rideConfirm == true ||
|
||||
// statusRide == 'Apply' ||
|
||||
// statusRide == 'Applied' ||
|
||||
// statusRide == 'wait' ||
|
||||
// statusRide == 'waiting') {
|
||||
clearPlacesDestination();
|
||||
clearPolyline();
|
||||
// clearPolylineAll();
|
||||
data = [];
|
||||
changeCancelRidePageShow();
|
||||
if (rideId != 'yet') {
|
||||
Log.print('cancelRide: 1');
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Cancel Trip'.tr,
|
||||
'Trip Cancelled'.tr,
|
||||
driverToken,
|
||||
[],
|
||||
'cancel.wav',
|
||||
);
|
||||
|
||||
await Future.wait([
|
||||
CRUD().post(link: AppLink.updateRides, payload: {
|
||||
"id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
});
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(
|
||||
link: "${AppLink.endPoint}/ride/rides/update.php",
|
||||
payload: {
|
||||
"id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
});
|
||||
}
|
||||
|
||||
}),
|
||||
CRUD().post(link: AppLink.updateDriverOrder, payload: {
|
||||
"order_id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
}),
|
||||
CRUD().post(link: AppLink.updateWaitingTrip, payload: {
|
||||
"id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
}),
|
||||
]);
|
||||
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(
|
||||
link: "${AppLink.endPoint}/ride/driver_order/update.php",
|
||||
payload: {
|
||||
"order_id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
});
|
||||
CRUD()
|
||||
.post(link: "${AppLink.endPoint}/ride/rides/update.php", payload: {
|
||||
"id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
});
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(
|
||||
link:
|
||||
"${AppLink.endPoint}/ride/notificationCaptain/updateWaitingTrip.php",
|
||||
payload: {
|
||||
"id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
});
|
||||
}
|
||||
|
||||
print('Cancel');
|
||||
CRUD().post(
|
||||
link:
|
||||
"${AppLink.endPoint}/ride/notificationCaptain/updateWaitingTrip.php",
|
||||
payload: {
|
||||
"id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
});
|
||||
}
|
||||
|
||||
Get.offAll(const MapPagePassenger());
|
||||
} else {
|
||||
clearPlacesDestination();
|
||||
clearPolyline();
|
||||
data = [];
|
||||
// await CRUD().post(link: AppLink.updateDriverOrder, payload: {
|
||||
// "order_id": rideId.toString(), // Convert to String
|
||||
// "status": 'Cancel'
|
||||
// });
|
||||
// await CRUD().post(link: AppLink.updateRides, payload: {
|
||||
// "id": rideId.toString(), // Convert to String
|
||||
// "status": 'Cancel'
|
||||
// });
|
||||
Get.offAll(const MapPagePassenger());
|
||||
print('Cancel');
|
||||
// }
|
||||
}
|
||||
Future.delayed(const Duration(seconds: 1));
|
||||
Get.offAll(() => const MapPagePassenger());
|
||||
}
|
||||
|
||||
void changePickerShown() {
|
||||
@@ -2942,28 +3309,28 @@ class MapPassengerController extends GetxController {
|
||||
? LatLng(_locationData.latitude!, _locationData.longitude!)
|
||||
: null)!;
|
||||
getLocationArea(passengerLocation.latitude, passengerLocation.longitude);
|
||||
Log.print('AppLink.endPoint: ${AppLink.endPoint}');
|
||||
// Log.print('BoxName.serverChosen: ${box.read(BoxName.serverChosen)}');
|
||||
|
||||
newStartPointLocation = passengerLocation;
|
||||
Log.print('passengerLocation: ${passengerLocation}');
|
||||
speed = _locationData.speed!;
|
||||
// //print location details
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
LatLngBounds calculateBounds(
|
||||
double centerLat, double centerLng, double radius) {
|
||||
// double radius = 4000; // 10 km in meters
|
||||
LatLngBounds calculateBounds(double lat, double lng, double radiusInMeters) {
|
||||
const double earthRadius = 6378137.0; // Earth's radius in meters
|
||||
|
||||
southwest = LatLng(
|
||||
centerLat - (radius / 111000),
|
||||
centerLng - (radius / (111000 * cos(centerLat))),
|
||||
double latDelta = radiusInMeters / earthRadius * (180 / pi);
|
||||
double lngDelta =
|
||||
radiusInMeters / (earthRadius * cos(pi * lat / 180)) * (180 / pi);
|
||||
|
||||
return LatLngBounds(
|
||||
southwest: LatLng(lat - latDelta, lng - lngDelta),
|
||||
northeast: LatLng(lat + latDelta, lng + lngDelta),
|
||||
);
|
||||
|
||||
northeast = LatLng(
|
||||
centerLat + (radius / 111000),
|
||||
centerLng + (radius / (111000 * cos(centerLat))),
|
||||
);
|
||||
|
||||
return LatLngBounds(southwest: southwest, northeast: northeast);
|
||||
}
|
||||
|
||||
GoogleMapController? mapController;
|
||||
@@ -2992,8 +3359,6 @@ class MapPassengerController extends GetxController {
|
||||
bool reloadStartApp = false;
|
||||
int reloadCount = 0;
|
||||
startMarkerReloading() async {
|
||||
Log.print('AppLink.endPoint: ${AppLink.endPoint}');
|
||||
|
||||
if (reloadStartApp == false) {
|
||||
Timer.periodic(const Duration(seconds: 5), (timer) async {
|
||||
reloadCount++;
|
||||
@@ -3233,7 +3598,7 @@ class MapPassengerController extends GetxController {
|
||||
remainingTime = 25; //to make cancel every call
|
||||
// startCarLocationSearch(box.read(BoxName.carType));
|
||||
await getCarsLocationByPassengerAndReloadMarker(
|
||||
box.read(BoxName.carType), 7000);
|
||||
box.read(BoxName.carType), 5000);
|
||||
// await getCarsLocationByPassengerAndReloadMarker();
|
||||
var coordDestination = destination.split(',');
|
||||
double latPassengerDestination = double.parse(coordDestination[0]);
|
||||
@@ -4093,55 +4458,77 @@ class MapPassengerController extends GetxController {
|
||||
try {
|
||||
// Prepare trip data
|
||||
Map<String, dynamic> tripData = {
|
||||
'id': driver['id'],
|
||||
'id': driver['id'].toString(), // Ensure the id is a string
|
||||
'phone': driver['phone'],
|
||||
'gender': driver['gender'],
|
||||
'name': driver['name'],
|
||||
'name': driver['NAME'],
|
||||
'name_english': driver['name_english'],
|
||||
'address': driver['address'],
|
||||
'religion': driver['religion'],
|
||||
'age': driver['age'],
|
||||
'age': driver['age'].toString(), // Convert age to String
|
||||
'education': driver['education'],
|
||||
'license_type': driver['license_type'],
|
||||
'national_number': driver['national_number'],
|
||||
'car_plate': driver['car_plate'],
|
||||
'make': driver['make'],
|
||||
'model': driver['model'],
|
||||
'year': driver['year'],
|
||||
'year': driver['year'].toString(), // Convert year to String
|
||||
'color': driver['color'],
|
||||
'color_hex': driver['color_hex'],
|
||||
'displacement': driver['displacement'],
|
||||
'fuel': driver['fuel'],
|
||||
'token': driver['token'],
|
||||
'rating': driver['rating'],
|
||||
'countRide': driver['countRide'],
|
||||
'rating': driver['rating'].toString(), // Convert rating to String
|
||||
'countRide':
|
||||
driver['countRide'].toString(), // Convert countRide to String
|
||||
'passengerId': box.read(BoxName.passengerID),
|
||||
'timeSelected': tripDateTime.toIso8601String(),
|
||||
'status': 'pending', // Or other appropriate status
|
||||
'status': 'pending',
|
||||
};
|
||||
// Log.print('tripData: $tripData');
|
||||
|
||||
// Send data to server
|
||||
var response =
|
||||
await CRUD().post(link: AppLink.addMishwari, payload: tripData);
|
||||
// Log.print('response: $response');
|
||||
|
||||
if (response != 'failure') {
|
||||
// Trip saved successfully
|
||||
Get.snackbar('Success'.tr, 'Trip booked successfully'.tr);
|
||||
var id = response['message'].toString();
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(
|
||||
await CRUD().post(
|
||||
link: "${AppLink.endPoint}/ride/mishwari/add.php",
|
||||
payload: tripData);
|
||||
}
|
||||
// Set up local notification
|
||||
// Optionally, set up local notification or send a push notification
|
||||
// await setLocalNotification(tripDateTime);
|
||||
|
||||
// Send notification to driver
|
||||
// await FirebaseMessagesController().sendNotificationToDriverMAP();
|
||||
await FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'OrderVIP',
|
||||
rideId.toString(),
|
||||
driver['token'].toString(),
|
||||
[
|
||||
id,
|
||||
driver['id'],
|
||||
passengerLocation.latitude.toString(),
|
||||
passengerLocation.longitude.toString(),
|
||||
box.read(BoxName.name).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');
|
||||
} else {
|
||||
throw Exception('Failed to save trip');
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar('Error'.tr, 'Failed to book trip: $e'.tr);
|
||||
// Show error message with more details for debugging
|
||||
Get.snackbar('Error'.tr, 'Failed to book trip: $e'.tr,
|
||||
backgroundColor: AppColor.redColor);
|
||||
Log.print('Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4253,8 +4640,8 @@ class MapPassengerController extends GetxController {
|
||||
addCustomStepIcon();
|
||||
addCustomStartIcon();
|
||||
addCustomEndIcon();
|
||||
addToken();
|
||||
getLocation();
|
||||
// addToken();
|
||||
await getLocation();
|
||||
getPassengerLocationUniversity();
|
||||
_initializePolygons();
|
||||
// await addToken();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:SEFER/views/widgets/my_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
@@ -9,11 +12,38 @@ import 'package:SEFER/constant/style.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
|
||||
import '../../../constant/api_key.dart';
|
||||
import '../../../print.dart';
|
||||
|
||||
class ComplaintController extends GetxController {
|
||||
bool isLoading = false;
|
||||
final formKey = GlobalKey<FormState>();
|
||||
final complaintController = TextEditingController();
|
||||
final suggestionController = TextEditingController();
|
||||
List feedBack = [];
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
getLatestRidesForPassengers();
|
||||
}
|
||||
|
||||
getLatestRidesForPassengers() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
var res = await CRUD().get(link: AppLink.getFeedBack, payload: {
|
||||
'passengerId': box.read(BoxName.passengerID).toString(),
|
||||
});
|
||||
if (res != 'failure') {
|
||||
var d = jsonDecode(res)['message'];
|
||||
feedBack = d;
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void addComplaint() async {
|
||||
isLoading = true;
|
||||
@@ -34,11 +64,175 @@ class ComplaintController extends GetxController {
|
||||
title: 'Ok'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
Get.back();
|
||||
// Get.back();
|
||||
}));
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
var isUploading = false.obs;
|
||||
var uploadSuccess = false.obs;
|
||||
late String audioLink = '';
|
||||
Future<void> uploadAudioFile(File audioFile) async {
|
||||
try {
|
||||
isUploading.value = true;
|
||||
|
||||
// Prepare the file upload
|
||||
var uri = Uri.parse('${AppLink.seferCairoServer}/upload_audio.php');
|
||||
var request = http.MultipartRequest('POST', uri);
|
||||
|
||||
// Add the file to the request with MIME type
|
||||
var mimeType = lookupMimeType(audioFile.path);
|
||||
request.headers.addAll({
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
|
||||
});
|
||||
request.files.add(
|
||||
await http.MultipartFile.fromPath(
|
||||
'audio',
|
||||
audioFile.path,
|
||||
contentType: mimeType != null ? MediaType.parse(mimeType) : null,
|
||||
),
|
||||
);
|
||||
|
||||
// Send the request
|
||||
var response = await request.send();
|
||||
|
||||
// Convert response to string for parsing
|
||||
var responseBody = await http.Response.fromStream(response);
|
||||
|
||||
// After the upload request
|
||||
if (response.statusCode == 200) {
|
||||
var jsonResponse = jsonDecode(responseBody.body);
|
||||
|
||||
if (jsonResponse['status'] == 'Audio file uploaded successfully.') {
|
||||
uploadSuccess.value = true;
|
||||
audioLink = jsonResponse['link']; // Get the audio link
|
||||
Get.back();
|
||||
Get.snackbar('Success'.tr, 'Audio uploaded successfully.'.tr,
|
||||
backgroundColor: const Color.fromARGB(255, 89, 185, 115));
|
||||
} else {
|
||||
uploadSuccess.value = false;
|
||||
}
|
||||
} else {
|
||||
uploadSuccess.value = false;
|
||||
}
|
||||
} catch (e) {
|
||||
uploadSuccess.value = false;
|
||||
} finally {
|
||||
isUploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
var customerServiceSolutions;
|
||||
var passengerReport;
|
||||
var driverReport;
|
||||
var isloading = false;
|
||||
Future<void> geminiAudio(payload, String audioLink, String complain) async {
|
||||
String prompt = '''
|
||||
Analyze the following complaint between a passenger and driver in a ride-hailing service. The complaint includes an audio link for reference. Provide two possible solutions for customer service to resolve the issue, and generate a detailed report for both the passenger and the driver.
|
||||
|
||||
Complaint details:
|
||||
- Passenger: $complain
|
||||
- Driver: [Driver's complaint]
|
||||
- Ride Information: {ride details such as start_location, end_location, date, price, status, and rating details}
|
||||
- Audio Link: [$audioLink]
|
||||
|
||||
Output the result in JSON format with the following structure:
|
||||
{
|
||||
"customerServiceSolutions": [
|
||||
"solution1",
|
||||
"solution2"
|
||||
],
|
||||
"passengerReport": {
|
||||
"solution": "Passenger's solution" if passenger right,
|
||||
"complaint": "Passenger's complaint",
|
||||
"rideDetails": {detailed ride info}
|
||||
},
|
||||
"driverReport": {
|
||||
"complaint": "Driver's complaint",
|
||||
"rideDetails": {detailed ride info}
|
||||
}
|
||||
} the response in arabic language with egypt
|
||||
''';
|
||||
|
||||
var requestBody = jsonEncode({
|
||||
"contents": [
|
||||
{
|
||||
"parts": [
|
||||
{"text": "$payload $prompt"}
|
||||
]
|
||||
}
|
||||
],
|
||||
"generationConfig": {
|
||||
"temperature": 1,
|
||||
"topK": 64,
|
||||
"topP": 0.95,
|
||||
"maxOutputTokens": 8192,
|
||||
"stopSequences": []
|
||||
},
|
||||
"safetySettings": [
|
||||
{
|
||||
"category": "HARM_CATEGORY_HARASSMENT",
|
||||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_HATE_SPEECH",
|
||||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro:generateContent?key=${AK.geminiApi}'),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: requestBody,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
var result = responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
Log.print('result: ${result}');
|
||||
|
||||
// Clean up the result by removing surrounding backticks if they exist
|
||||
result = result.replaceAll(RegExp(r'^```json\s*|\s*```$'), '');
|
||||
|
||||
// Attempt to decode the cleaned result as JSON
|
||||
try {
|
||||
var jsonResult = jsonDecode(result);
|
||||
|
||||
// Access customer service solutions and reports for both passenger and driver
|
||||
customerServiceSolutions = jsonResult['customerServiceSolutions'];
|
||||
passengerReport = jsonResult['passengerReport'];
|
||||
driverReport = jsonResult['driverReport'];
|
||||
update();
|
||||
// Use the data accordingly
|
||||
// For example, log the reports or display them in a UI dialog
|
||||
|
||||
update();
|
||||
} catch (e) {
|
||||
MyDialog().getDialog(
|
||||
'Error'.tr,
|
||||
'Unable to parse the response as JSON. Please check the format and try again.'
|
||||
.tr, () {
|
||||
Get.back();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Get.snackbar(
|
||||
'Error', "Request failed with status: ${response.statusCode}",
|
||||
backgroundColor: AppColor.redColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
280
lib/controller/home/profile/invit_controller.dart
Normal file
280
lib/controller/home/profile/invit_controller.dart
Normal file
@@ -0,0 +1,280 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/controller/home/payment/captain_wallet_controller.dart';
|
||||
import 'package:SEFER/controller/payment/payment_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/contact.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:share/share.dart';
|
||||
|
||||
import '../../../main.dart';
|
||||
import '../../../views/widgets/my_dialog.dart';
|
||||
import '../../functions/launch.dart';
|
||||
import '../../notification/notification_captain_controller.dart';
|
||||
|
||||
class InviteController extends GetxController {
|
||||
final TextEditingController invitePhoneController = TextEditingController();
|
||||
List driverInvitationData = [];
|
||||
List driverInvitationDataToPassengers = [];
|
||||
String? couponCode;
|
||||
String? driverCouponCode;
|
||||
|
||||
int selectedTab = 0;
|
||||
PassengerStats passengerStats = PassengerStats();
|
||||
void updateSelectedTab(int index) {
|
||||
selectedTab = index;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> shareCouponCode() async {
|
||||
// TODO: Implement sharing functionality
|
||||
// You can use share_plus package to share the coupon code
|
||||
}
|
||||
Future<void> shareDriverCode() async {
|
||||
if (driverCouponCode != null) {
|
||||
final String shareText = '''
|
||||
Join SEFER as a driver using my referral code!
|
||||
Use code: $driverCouponCode
|
||||
Download the SEFER Driver app now and earn rewards!
|
||||
''';
|
||||
await Share.share(shareText);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> sharePassengerCode() async {
|
||||
if (couponCode != null) {
|
||||
final String shareText = '''
|
||||
Get a discount on your first SEFER ride!
|
||||
Use my referral code: $couponCode
|
||||
Download the SEFER app now and enjoy your ride!
|
||||
''';
|
||||
await Share.share(shareText);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
// fetchDriverStats();
|
||||
}
|
||||
|
||||
void fetchDriverStats() async {
|
||||
try {
|
||||
var response = await CRUD().get(link: AppLink.getInviteDriver, payload: {
|
||||
"driverId": box.read(BoxName.driverID),
|
||||
});
|
||||
if (response != 'failure') {
|
||||
var data = jsonDecode(response);
|
||||
driverInvitationData = data['message'];
|
||||
update();
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
void fetchDriverStatsPassengers() async {
|
||||
try {
|
||||
var response = await CRUD()
|
||||
.get(link: AppLink.getDriverInvitationToPassengers, payload: {
|
||||
"driverId": box.read(BoxName.passengerID),
|
||||
});
|
||||
if (response != 'failure') {
|
||||
var data = jsonDecode(response);
|
||||
driverInvitationDataToPassengers = data['message'];
|
||||
update();
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
void selectPhone(String phone) {
|
||||
if (box.read(BoxName.countryCode) == 'Egypt') {
|
||||
invitePhoneController.text = phone;
|
||||
update();
|
||||
Get.back();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveContactsToServer() async {
|
||||
try {
|
||||
// TODO: Implement the actual server upload logic here
|
||||
// Simulating a server request
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
Get.snackbar('Success'.tr,
|
||||
'${selectedContacts.length} contacts saved to server'.tr);
|
||||
} catch (e) {
|
||||
Get.snackbar('Error'.tr,
|
||||
'An error occurred while saving contacts to server: $e'.tr);
|
||||
}
|
||||
}
|
||||
|
||||
List<Contact> contacts = <Contact>[];
|
||||
List<Contact> selectedContacts = <Contact>[];
|
||||
RxList<Map<String, dynamic>> contactMaps = <Map<String, dynamic>>[].obs;
|
||||
|
||||
Future<void> pickContacts() async {
|
||||
try {
|
||||
if (await FlutterContacts.requestPermission(readonly: true)) {
|
||||
final List<Contact> fetchedContacts =
|
||||
await FlutterContacts.getContacts(withProperties: true);
|
||||
contacts = fetchedContacts;
|
||||
|
||||
// Convert contacts to a list of maps
|
||||
contactMaps.value = fetchedContacts.map((contact) {
|
||||
return {
|
||||
'name': contact.displayName,
|
||||
'phones':
|
||||
contact.phones.map((phone) => phone.normalizedNumber).toList(),
|
||||
'emails': contact.emails.map((email) => email.address).toList(),
|
||||
};
|
||||
}).toList();
|
||||
update();
|
||||
|
||||
if (contacts.isEmpty) {
|
||||
Get.snackbar('No contacts available'.tr,
|
||||
'Please add contacts to your phone.'.tr);
|
||||
}
|
||||
} else {
|
||||
Get.snackbar('Permission denied'.tr,
|
||||
'Contact permission is required to pick contacts'.tr);
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar(
|
||||
'Error'.tr, 'An error occurred while picking contacts: $e'.tr);
|
||||
}
|
||||
}
|
||||
|
||||
void onSelectPassengerInvitation(int index) async {
|
||||
MyDialog().getDialog(
|
||||
driverInvitationDataToPassengers[index]['countOfInvitDriver'] < 2
|
||||
? '${'When'.tr} ${driverInvitationDataToPassengers[index]['passengerName']} ${"complete, you can claim your gift".tr} '
|
||||
: 'You deserve the gift'.tr,
|
||||
'${driverInvitationDataToPassengers[index]['passengerName']} ${driverInvitationDataToPassengers[index]['countOfInvitDriver']} / 2 ${'Trip'.tr}',
|
||||
() async {
|
||||
if (driverInvitationDataToPassengers[index]['countOfInvitDriver'] < 2) {
|
||||
Get.back();
|
||||
} else {
|
||||
// Claim the gift if 100 trips are completed
|
||||
if (driverInvitationDataToPassengers[index]['isGiftToken']
|
||||
.toString() ==
|
||||
'0') {
|
||||
Get.back();
|
||||
// Add wallet to the inviter
|
||||
await Get.find<PaymentController>().addPassengersWallet('20');
|
||||
// add for invitor too
|
||||
// await Get.find<CaptainWalletController>().addDriverWalletToInvitor(
|
||||
// 'paymentMethod',
|
||||
// driverInvitationData[index]['driverInviterId'],
|
||||
// '50');
|
||||
// Update invitation as claimed
|
||||
await CRUD().post(
|
||||
link: AppLink.updatePassengerGift,
|
||||
payload: {'id': driverInvitationDataToPassengers[index]['id']},
|
||||
);
|
||||
// Notify the inviter
|
||||
NotificationCaptainController().addNotificationCaptain(
|
||||
driverInvitationDataToPassengers[index]['passengerInviterId']
|
||||
.toString(),
|
||||
"You have got a gift for invitation".tr,
|
||||
'${"You have 20".tr} ${'LE'}',
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
Get.back();
|
||||
MyDialog().getDialog(
|
||||
"You have got a gift".tr,
|
||||
"Share the app with another new passenger".tr,
|
||||
() {
|
||||
Get.back();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
savePhoneToServer() async {
|
||||
for (var i = 0; i < contactMaps.length; i++) {
|
||||
var phones = contactMaps[i]['phones'];
|
||||
if (phones != null && phones.isNotEmpty && phones[0].isNotEmpty) {
|
||||
var res = await CRUD().post(link: AppLink.savePhones, payload: {
|
||||
"name": contactMaps[i]['name'] ?? 'none',
|
||||
"phones": phones[0] ?? 'none',
|
||||
"phones2": phones.join(', ') ??
|
||||
'none', // Convert List<String> to a comma-separated string
|
||||
});
|
||||
if (res != 'failure') {}
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
|
||||
String formatPhoneNumber(String input) {
|
||||
// Remove any non-digit characters
|
||||
String digitsOnly = input.replaceAll(RegExp(r'\D'), '');
|
||||
|
||||
// Ensure the number starts with the country code
|
||||
if (digitsOnly.startsWith('20')) {
|
||||
digitsOnly = digitsOnly.substring(1);
|
||||
}
|
||||
|
||||
return digitsOnly;
|
||||
}
|
||||
|
||||
void sendInviteToPassenger() async {
|
||||
if (invitePhoneController.text.isEmpty) {
|
||||
Get.snackbar('Error', 'Please enter an phone address'.tr);
|
||||
return;
|
||||
}
|
||||
|
||||
// try {
|
||||
String phoneNumber = formatPhoneNumber(invitePhoneController.text);
|
||||
|
||||
var response =
|
||||
await CRUD().post(link: AppLink.addInvitationPassenger, payload: {
|
||||
"driverId": box.read(BoxName.passengerID),
|
||||
"inviterPassengerPhone": '+2$phoneNumber'
|
||||
});
|
||||
|
||||
if (response != 'failure') {
|
||||
var d = jsonDecode(response);
|
||||
Get.snackbar('Success', 'Invite sent successfully'.tr);
|
||||
|
||||
String message = '${'*SEFER APP CODE*'.tr}\n\n'
|
||||
'${"Use this code in registration".tr}\n'
|
||||
'${"To get a gift for both".tr}\n\n'
|
||||
'${"The period of this code is 1 hour".tr}\n\n'
|
||||
'${'before'.tr} *${d['message']['expirationTime'].toString()}*\n\n'
|
||||
'_*${d['message']['inviteCode'].toString()}*_\n\n'
|
||||
'${"Install our app:".tr}\n'
|
||||
'*Android:* https://play.google.com/store/apps/details?id=com.mobileapp.store.ride\n\n\n'
|
||||
'*iOS:* https://apps.apple.com/us/app/sefer/id6458734951';
|
||||
|
||||
launchCommunication('whatsapp', '+2$phoneNumber', message);
|
||||
|
||||
invitePhoneController.clear();
|
||||
} else {
|
||||
Get.snackbar('Error'.tr, "Invite code already used".tr,
|
||||
backgroundColor: AppColor.redColor,
|
||||
duration: const Duration(seconds: 4));
|
||||
}
|
||||
// } catch (e) {
|
||||
// Get.snackbar('Error', 'An error occurred'.tr);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
class PassengerStats {
|
||||
final int totalInvites;
|
||||
final int activeUsers;
|
||||
final double totalEarnings;
|
||||
|
||||
PassengerStats({
|
||||
this.totalInvites = 0,
|
||||
this.activeUsers = 0,
|
||||
this.totalEarnings = 0.0,
|
||||
});
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/constant/style.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../../main.dart';
|
||||
|
||||
class PromosController extends GetxController {
|
||||
List<dynamic> promoList = [];
|
||||
@@ -17,7 +18,9 @@ class PromosController extends GetxController {
|
||||
}
|
||||
|
||||
Future getPromoByToday() async {
|
||||
var res = await CRUD().get(link: AppLink.getPromoBytody, payload: {});
|
||||
var res = await CRUD().get(link: AppLink.getPromoBytody, payload: {
|
||||
'passengerID': box.read(BoxName.passengerID).toString(),
|
||||
});
|
||||
if (res.toString() == 'failure') {
|
||||
// Get.defaultDialog(
|
||||
// title: 'No Promo for today .'.tr,
|
||||
|
||||
Reference in New Issue
Block a user