9/8/1
This commit is contained in:
@@ -233,7 +233,7 @@ class MapPassengerController extends GetxController {
|
||||
late double totalPassengerSpeedDiscount = 0;
|
||||
late double totalPassengerBalashDiscount = 0;
|
||||
late double totalPassengerRaihGaiDiscount = 0;
|
||||
late double totalPassengerMotoDelivery = 0;
|
||||
late double totalPassengerScooter = 0;
|
||||
late double totalDriver = 0;
|
||||
late double averageDuration = 0;
|
||||
late double costDuration = 0;
|
||||
@@ -258,7 +258,7 @@ class MapPassengerController extends GetxController {
|
||||
void getCurrentLocationFormString() async {
|
||||
currentLocationToFormPlaces = true;
|
||||
currentLocationString = 'Waiting for your location'.tr;
|
||||
await getLocation();
|
||||
getLocation();
|
||||
currentLocationString = passengerLocation.toString();
|
||||
newStartPointLocation = passengerLocation;
|
||||
update();
|
||||
@@ -1760,7 +1760,7 @@ class MapPassengerController extends GetxController {
|
||||
'northeastLon': bounds.northeast.longitude.toString(),
|
||||
});
|
||||
break;
|
||||
case 'Delivery':
|
||||
case 'Scooter':
|
||||
res = await CRUD()
|
||||
.get(link: AppLink.getCarsLocationByPassengerDelivery, payload: {
|
||||
'southwestLat': bounds.southwest.latitude.toString(),
|
||||
@@ -2603,44 +2603,58 @@ class MapPassengerController extends GetxController {
|
||||
Future<void> getLocation() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
bool serviceEnabled;
|
||||
PermissionStatus permissionGranted;
|
||||
// dialoge();
|
||||
// Check if location services are enabled
|
||||
serviceEnabled = await location.serviceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
serviceEnabled = await location.requestService();
|
||||
|
||||
try {
|
||||
// Perform permission and service checks in parallel
|
||||
final results = await Future.wait([
|
||||
location.serviceEnabled(),
|
||||
location.hasPermission(),
|
||||
]);
|
||||
|
||||
bool serviceEnabled = results[0] as bool; // Cast to bool
|
||||
PermissionStatus permissionGranted =
|
||||
results[1] as PermissionStatus; // Cast to PermissionStatus
|
||||
|
||||
// Check if location services are enabled
|
||||
if (!serviceEnabled) {
|
||||
// Location services are still not enabled, handle the error
|
||||
return;
|
||||
serviceEnabled = await location.requestService();
|
||||
if (!serviceEnabled) {
|
||||
// Location services are still not enabled, handle the error
|
||||
isLoading = false;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the app has permission to access location
|
||||
permissionGranted = await location.hasPermission();
|
||||
if (permissionGranted == PermissionStatus.denied) {
|
||||
permissionGranted = await location.requestPermission();
|
||||
if (permissionGranted != PermissionStatus.granted) {
|
||||
// Location permission is still not granted, handle the error
|
||||
return;
|
||||
// Check if the app has permission to access location
|
||||
if (permissionGranted == PermissionStatus.denied) {
|
||||
permissionGranted = await location.requestPermission();
|
||||
if (permissionGranted != PermissionStatus.granted) {
|
||||
// Location permission is still not granted, handle the error
|
||||
isLoading = false;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Request updated location with medium accuracy (faster)
|
||||
LocationData _locationData = await location.getLocation();
|
||||
passengerLocation =
|
||||
LatLng(_locationData.latitude!, _locationData.longitude!);
|
||||
|
||||
// Process location data
|
||||
getLocationArea(passengerLocation.latitude, passengerLocation.longitude);
|
||||
newStartPointLocation = passengerLocation;
|
||||
speed = _locationData.speed!;
|
||||
|
||||
// Update loading state
|
||||
isLoading = false;
|
||||
update();
|
||||
} catch (e) {
|
||||
// Handle exceptions (optional logging)
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
// Configure location accuracy
|
||||
// LocationAccuracy desiredAccuracy = LocationAccuracy.high;
|
||||
|
||||
// Get the current location
|
||||
LocationData _locationData = await location.getLocation();
|
||||
passengerLocation =
|
||||
(_locationData.latitude != null && _locationData.longitude != null
|
||||
? LatLng(_locationData.latitude!, _locationData.longitude!)
|
||||
: null)!;
|
||||
getLocationArea(passengerLocation.latitude, passengerLocation.longitude);
|
||||
newStartPointLocation = passengerLocation;
|
||||
speed = _locationData.speed!;
|
||||
// //print location details
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
LatLngBounds calculateBounds(
|
||||
@@ -2689,7 +2703,7 @@ class MapPassengerController extends GetxController {
|
||||
Log.print('AppLink.endPoint: ${AppLink.endPoint}');
|
||||
|
||||
if (reloadStartApp == false) {
|
||||
Timer.periodic(const Duration(seconds: 5), (timer) async {
|
||||
Timer.periodic(const Duration(seconds: 4), (timer) async {
|
||||
reloadCount++;
|
||||
Log.print('reloadCount: ${reloadCount}');
|
||||
|
||||
@@ -2762,7 +2776,7 @@ class MapPassengerController extends GetxController {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3195,7 +3209,7 @@ class MapPassengerController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
int selectedIndex = -1; // Initialize with no selection
|
||||
int selectedIndex = 1; // Initialize with no selection
|
||||
void selectCarFromList(int index) {
|
||||
selectedIndex = index; // Update selected index
|
||||
carTypes.forEach(
|
||||
@@ -3269,6 +3283,8 @@ class MapPassengerController extends GetxController {
|
||||
double totalPassengerBalash = 0;
|
||||
double totalPassengerLady = 0;
|
||||
double totalPassengerRayehGai = 0;
|
||||
double totalPassengerRayehGaiComfort = 0;
|
||||
double totalPassengerRayehGaiBalash = 0;
|
||||
Future bottomSheet() async {
|
||||
if (data.isNotEmpty) {
|
||||
durationToAdd = Duration(seconds: durationToRide);
|
||||
@@ -3285,7 +3301,9 @@ class MapPassengerController extends GetxController {
|
||||
costDelivery,
|
||||
costBalash,
|
||||
costLady,
|
||||
costRayehGai = 0;
|
||||
costRayehGai,
|
||||
costRayehGaiBalash,
|
||||
costRayehGaiComfort = 0;
|
||||
update();
|
||||
if (startNameAddress.toLowerCase().contains('airport') ||
|
||||
endNameAddress.toLowerCase().contains('airport') ||
|
||||
@@ -3306,10 +3324,17 @@ class MapPassengerController extends GetxController {
|
||||
((distance * 1 * speedPrice) * .4) +
|
||||
costDuration * 2 * latePrice +
|
||||
20;
|
||||
costRayehGaiComfort = (distance * 2 * comfortPrice) -
|
||||
((distance * 1 * comfortPrice) * .4) +
|
||||
costDuration * 2 * latePrice +
|
||||
20;
|
||||
costRayehGaiBalash = (distance * 2 * (speedPrice - 1)) -
|
||||
((distance * 1 * (speedPrice - 1)) * .4) +
|
||||
costDuration * 2 * latePrice +
|
||||
20;
|
||||
|
||||
update();
|
||||
}
|
||||
if (currentTime.hour >= 21 && currentTime.hour < 0) {
|
||||
} else if (currentTime.hour >= 21 && currentTime.hour < 0) {
|
||||
// costDistance = distance * latePrice;
|
||||
costComfort = (distance * comfortPrice) + costDuration * latePrice;
|
||||
costSpeed = (distance * speedPrice) + costDuration * latePrice;
|
||||
@@ -3319,6 +3344,12 @@ class MapPassengerController extends GetxController {
|
||||
costRayehGai = (distance * 2 * speedPrice) -
|
||||
((distance * 1 * speedPrice) * .4) +
|
||||
costDuration * 2 * latePrice;
|
||||
costRayehGaiComfort = (distance * 2 * comfortPrice) -
|
||||
((distance * 1 * comfortPrice) * .4) +
|
||||
costDuration * 2 * latePrice;
|
||||
costRayehGaiBalash = (distance * 2 * (speedPrice - 1)) -
|
||||
((distance * 1 * (speedPrice - 1)) * .4) +
|
||||
costDuration * 2 * latePrice;
|
||||
|
||||
update();
|
||||
} else if (currentTime.hour >= 1 && currentTime.hour < 5) {
|
||||
@@ -3328,8 +3359,9 @@ class MapPassengerController extends GetxController {
|
||||
startNameAddress.contains('ديسكو') ||
|
||||
startNameAddress.contains('ملهى ليلي') ||
|
||||
startNameAddress.contains('Night club')) {
|
||||
// Your code here costComfort =
|
||||
(distance * comfortPrice) + costDuration * (latePrice + .5) * 2;
|
||||
// Your code here
|
||||
costComfort =
|
||||
(distance * comfortPrice) + costDuration * (latePrice + .5) * 2;
|
||||
costSpeed =
|
||||
(distance * speedPrice) + costDuration * (latePrice + .5) * 2;
|
||||
costBalash = (distance * (speedPrice - 1)) +
|
||||
@@ -3341,6 +3373,12 @@ class MapPassengerController extends GetxController {
|
||||
costRayehGai = (distance * 2 * speedPrice) -
|
||||
((distance * 1 * speedPrice) * .4) +
|
||||
costDuration * 2 * (latePrice + .5) * 2;
|
||||
costRayehGaiComfort = (distance * 2 * comfortPrice) -
|
||||
((distance * 1 * comfortPrice) * .4) +
|
||||
costDuration * 2 * (latePrice + .5) * 2;
|
||||
costRayehGaiBalash = (distance * 2 * (speedPrice - 1)) -
|
||||
((distance * 1 * (speedPrice - 1)) * .4) +
|
||||
costDuration * 2 * (latePrice + .5) * 2;
|
||||
|
||||
update();
|
||||
}
|
||||
@@ -3356,9 +3394,15 @@ class MapPassengerController extends GetxController {
|
||||
costRayehGai = (distance * 2 * speedPrice) -
|
||||
((distance * 1 * speedPrice) * .4) +
|
||||
costDuration * 2 * latePrice;
|
||||
costRayehGaiComfort = (distance * 2 * comfortPrice) -
|
||||
((distance * 1 * comfortPrice) * .4) +
|
||||
costDuration * 2 * latePrice;
|
||||
costRayehGaiBalash = (distance * 2 * (speedPrice - 1)) -
|
||||
((distance * 1 * (speedPrice - 1)) * .4) +
|
||||
costDuration * 2 * latePrice;
|
||||
|
||||
update();
|
||||
} else if (currentTime.hour >= 13 && currentTime.hour <= 16) {
|
||||
} else if (currentTime.hour >= 14 && currentTime.hour <= 17) {
|
||||
// if (averageDuration > 2.5) {
|
||||
// costDistance = distance * heavyPrice;
|
||||
costComfort = (distance * comfortPrice) + costDuration * heavyPrice;
|
||||
@@ -3369,6 +3413,12 @@ class MapPassengerController extends GetxController {
|
||||
costRayehGai = (distance * 2 * speedPrice) -
|
||||
((distance * 1 * speedPrice) * .4) +
|
||||
costDuration * 2 * heavyPrice;
|
||||
costRayehGaiComfort = (distance * 2 * comfortPrice) -
|
||||
((distance * 1 * comfortPrice) * .4) +
|
||||
costDuration * 2 * heavyPrice;
|
||||
costRayehGaiBalash = (distance * 2 * (speedPrice - 1)) -
|
||||
((distance * 1 * (speedPrice - 1)) * .4) +
|
||||
costDuration * 2 * heavyPrice;
|
||||
|
||||
update();
|
||||
// } /
|
||||
@@ -3382,6 +3432,12 @@ class MapPassengerController extends GetxController {
|
||||
costRayehGai = (distance * 2 * speedPrice) -
|
||||
((distance * 1 * speedPrice) * .4) +
|
||||
costDuration * 2;
|
||||
costRayehGaiComfort = (distance * 2 * comfortPrice) -
|
||||
((distance * 1 * comfortPrice) * .4) +
|
||||
costDuration * 2;
|
||||
costRayehGaiBalash = (distance * 2 * (speedPrice - 1)) -
|
||||
((distance * 1 * (speedPrice - 1)) * .4) +
|
||||
costDuration * 2;
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -3397,6 +3453,12 @@ class MapPassengerController extends GetxController {
|
||||
(costBalash + (costBalash * kazan / 100)).ceilToDouble();
|
||||
totalPassengerRayehGai =
|
||||
(costRayehGai + (costRayehGai * kazan / 100)).ceilToDouble();
|
||||
totalPassengerRayehGaiComfort =
|
||||
(costRayehGaiComfort + (costRayehGaiComfort * kazan / 100))
|
||||
.ceilToDouble();
|
||||
totalPassengerRayehGaiBalash =
|
||||
(costRayehGaiBalash + (costRayehGaiBalash * kazan / 100))
|
||||
.ceilToDouble();
|
||||
totalPassengerComfortDiscount =
|
||||
totalPassengerComfort + totalPassengerComfort * (kazan - 0) / 100;
|
||||
totalPassengerLadyDiscount =
|
||||
@@ -3407,7 +3469,7 @@ class MapPassengerController extends GetxController {
|
||||
totalPassengerBalash + totalPassengerBalash * (kazan) / 100;
|
||||
totalPassengerRaihGaiDiscount =
|
||||
totalPassengerRayehGai + totalPassengerRayehGai * (kazan) / 100;
|
||||
totalPassengerMotoDelivery =
|
||||
totalPassengerScooter =
|
||||
(costDelivery + (costDelivery * kazan / 100)).ceilToDouble();
|
||||
totalPassengerComfort = totalPassengerComfortDiscount -
|
||||
(totalPassengerComfortDiscount * kazan / 100);
|
||||
@@ -3428,7 +3490,7 @@ class MapPassengerController extends GetxController {
|
||||
totalPassengerBalash = 20;
|
||||
totalPassengerComfort = 30;
|
||||
totalPassengerLady = 30;
|
||||
totalPassengerMotoDelivery = 18;
|
||||
totalPassengerScooter = 18;
|
||||
} else {
|
||||
totalPassenger = totalCostPassenger;
|
||||
update();
|
||||
@@ -3442,7 +3504,9 @@ class MapPassengerController extends GetxController {
|
||||
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
|
||||
totalPassengerBalash = totalPassengerBalash +
|
||||
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
|
||||
totalPassengerMotoDelivery = totalPassengerMotoDelivery +
|
||||
totalPassengerScooter = totalPassengerScooter +
|
||||
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
|
||||
totalPassengerRayehGai = totalPassengerScooter +
|
||||
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
|
||||
update();
|
||||
}
|
||||
@@ -3559,50 +3623,79 @@ class MapPassengerController extends GetxController {
|
||||
try {
|
||||
// Prepare trip data
|
||||
Map<String, dynamic> tripData = {
|
||||
'id': driver['id'],
|
||||
'phone': driver['phone'],
|
||||
'gender': driver['gender'],
|
||||
'name': driver['name'],
|
||||
'name_english': driver['name_english'],
|
||||
'address': driver['address'],
|
||||
'driverId': driver['id'].toString(),
|
||||
'phone': driver['phone'].toString(),
|
||||
'gender': driver['gender'].toString(),
|
||||
'name': driver['NAME']
|
||||
.toString(), // Confirm this key exists in the driver map
|
||||
'name_english': driver['name_english'].toString(),
|
||||
'address': driver['address'].toString(),
|
||||
'religion': driver['religion'],
|
||||
'age': driver['age'],
|
||||
'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'],
|
||||
'color': driver['color'],
|
||||
'color_hex': driver['color_hex'],
|
||||
'displacement': driver['displacement'],
|
||||
'fuel': driver['fuel'],
|
||||
'token': driver['token'],
|
||||
'rating': driver['rating'],
|
||||
'countRide': driver['countRide'],
|
||||
'passengerId': box.read(BoxName.passengerID),
|
||||
'timeSelected': tripDateTime.toIso8601String(),
|
||||
'status': 'pending', // Or other appropriate status
|
||||
'age': driver['age'].toString(),
|
||||
'education': driver['education'].toString(),
|
||||
'license_type': driver['license_type'].toString(),
|
||||
'national_number': driver['national_number'].toString(),
|
||||
'car_plate': driver['car_plate'].toString(),
|
||||
'make': driver['make'].toString(),
|
||||
'model': driver['model'].toString(),
|
||||
'color': driver['color'].toString(),
|
||||
'color_hex': driver['color_hex'].toString(),
|
||||
'token': driver['token'].toString(),
|
||||
'rating': driver['rating'].toString(),
|
||||
'countRide': driver['countRide'].toString(),
|
||||
'passengerId': box.read(BoxName.passengerID).toString(),
|
||||
'timeSelected': tripDateTime.toString(),
|
||||
'status': 'pending',
|
||||
};
|
||||
|
||||
Log.print('tripData prepared: $tripData');
|
||||
|
||||
// Send data to server
|
||||
var response =
|
||||
await CRUD().post(link: AppLink.addMishwari, payload: tripData);
|
||||
var response = await CRUD().post(
|
||||
link: AppLink.addMishwari,
|
||||
payload: tripData,
|
||||
);
|
||||
|
||||
if (response != 'failure') {
|
||||
// Trip saved successfully
|
||||
Get.snackbar('Success'.tr, 'Trip booked successfully'.tr);
|
||||
Log.print('Server response received: $response');
|
||||
|
||||
// Set up local notification
|
||||
// await setLocalNotification(tripDateTime);
|
||||
|
||||
// Send notification to driver
|
||||
// await FirebaseMessagesController().sendNotificationToDriverMAP();
|
||||
if (response != 'failure' && response != null) {
|
||||
Get.back();
|
||||
Future.delayed(Duration.zero);
|
||||
Get.defaultDialog(
|
||||
title: 'Success'.tr,
|
||||
middleText: 'Trip booked successfully'.tr,
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Accept'.tr,
|
||||
onPressed: () async {
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'VIP Order'.tr,
|
||||
'from: ${box.read(BoxName.name)}',
|
||||
driver['token'].toString(),
|
||||
[
|
||||
box.read(BoxName.tokenFCM).toString(),
|
||||
tripDateTime.toString()
|
||||
],
|
||||
'order.wav');
|
||||
Get.back();
|
||||
},
|
||||
kolor: AppColor.greenColor,
|
||||
));
|
||||
Get.snackbar('Success'.tr, 'Trip booked successfully'.tr,
|
||||
backgroundColor: AppColor.greenColor);
|
||||
} else {
|
||||
throw Exception('Failed to save trip');
|
||||
Get.back();
|
||||
MyDialog().getDialog(
|
||||
'Error'.tr,
|
||||
"Driver already has 2 trips within the specified period.".tr,
|
||||
() {});
|
||||
|
||||
Get.snackbar('Error'.tr, 'Trip booked successfully'.tr,
|
||||
backgroundColor: AppColor.redColor);
|
||||
Log.print('Error response from server: $response');
|
||||
throw Exception('Failed to save trip with response: $response');
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('Exception caught: $e');
|
||||
Get.snackbar('Error'.tr, 'Failed to book trip: $e'.tr);
|
||||
}
|
||||
}
|
||||
@@ -3679,7 +3772,7 @@ class MapPassengerController extends GetxController {
|
||||
addCustomStepIcon();
|
||||
addCustomStartIcon();
|
||||
addCustomEndIcon();
|
||||
await getLocation();
|
||||
getLocation();
|
||||
|
||||
// await addToken();
|
||||
getKazanPercent();
|
||||
|
||||
Reference in New Issue
Block a user