24-12/27/1

This commit is contained in:
Hamza-Ayed
2024-12-27 21:25:40 +03:00
parent d0dd09dc6c
commit f9f19c33ef
8 changed files with 423 additions and 683 deletions

View File

@@ -30,23 +30,22 @@ class OrderRequestController extends GetxController {
var myList;
late int hours;
late int minutes;
GoogleMapController? mapController; // Make it nullable
@override
Future<void> onInit() async {
// AudioController audioController = Get.put(AudioController());
print('onInit called');
await initilizeOrderPage();
print('OrderRequestController onInit called');
await initializeOrderPage();
bool isOverlayActive = await FlutterOverlayWindow.isActive();
if (isOverlayActive) {
await FlutterOverlayWindow.closeOverlay();
}
// audioController.playAudio();
// getRefusedOrderByCaptain();
addCustomStartIcon();
addCustomEndIcon();
// calculateConsumptionFuel();
startTimer(
myList[6].toString(),
myList[16].toString(),
);
update();
super.onInit();
}
@@ -59,16 +58,16 @@ class OrderRequestController extends GetxController {
late double lngPassengerDestination;
late double latPassengerDestination;
Future<void> initilizeOrderPage() async {
Future<void> initializeOrderPage() async {
final myListString = Get.arguments['myListString'];
if (Get.arguments['DriverList'] == null ||
Get.arguments['DriverList'].isEmpty) {
myList = jsonDecode(myListString);
Log.print('myList: ${myList}');
Log.print('myList from myListString: ${myList}');
} else {
myList = Get.arguments['DriverList'];
Log.print('myList1: ${myList}');
Log.print('myList from DriverList: ${myList}');
}
body = Get.arguments['body'];
@@ -78,36 +77,58 @@ class OrderRequestController extends GetxController {
minutes = (durationToAdd.inMinutes % 60).round();
startTimerSpeed(myList[6].toString(), body.toString());
// Instead of splitting, directly use the values from the list
// First coordinate pair is at index 0 and 1
latPassengerLocation = double.tryParse(myList[0]) ?? 0.0;
lngPassengerLocation = double.tryParse(myList[1]) ?? 0.0;
// --- Using the provided logic for initialization ---
var cords = myList[0].toString().split(',');
var cordDestination = myList[1].toString().split(',');
// Second coordinate pair is at index 2 and 3
latPassengerDestination = double.tryParse(myList[2]) ?? 0.0;
lngPassengerDestination = double.tryParse(myList[3]) ?? 0.0;
double? parseDouble(String value) {
try {
return double.parse(value);
} catch (e) {
Log.print("Error parsing value: $value");
return null; // or handle the error appropriately
}
}
latPassengerLocation = parseDouble(cords[0]) ?? 0.0;
lngPassengerLocation = parseDouble(cords[1]) ?? 0.0;
latPassengerDestination = parseDouble(cordDestination[0]) ?? 0.0;
lngPassengerDestination = parseDouble(cordDestination[1]) ?? 0.0;
pointsDirection = [
LatLng(latPassengerLocation, lngPassengerLocation),
LatLng(latPassengerDestination, lngPassengerDestination)
];
Log.print('pointsDirection: $pointsDirection');
// Calculate bounds
double minLatitude =
math.min(pointsDirection[0].latitude, pointsDirection[1].latitude);
double maxLatitude =
math.max(pointsDirection[0].latitude, pointsDirection[1].latitude);
double minLongitude =
math.min(pointsDirection[0].longitude, pointsDirection[1].longitude);
double maxLongitude =
math.max(pointsDirection[0].longitude, pointsDirection[1].longitude);
calculateBounds();
update();
}
void onMapCreated(GoogleMapController controller) {
mapController = controller;
animateCameraToBounds();
}
void calculateBounds() {
double minLat = math.min(latPassengerLocation, latPassengerDestination);
double maxLat = math.max(latPassengerLocation, latPassengerDestination);
double minLng = math.min(lngPassengerLocation, lngPassengerDestination);
double maxLng = math.max(lngPassengerLocation, lngPassengerDestination);
bounds = LatLngBounds(
southwest: LatLng(minLatitude, minLongitude),
northeast: LatLng(maxLatitude, maxLongitude),
southwest: LatLng(minLat, minLng),
northeast: LatLng(maxLat, maxLng),
);
Log.print('Calculated Bounds: $bounds');
}
update();
void animateCameraToBounds() {
if (mapController != null) {
mapController!.animateCamera(CameraUpdate.newLatLngBounds(bounds, 80.0));
} else {
Log.print('mapController is null, cannot animate camera.');
}
}
getRideDEtailsForBackgroundOrder(String rideId) async {
@@ -117,10 +138,7 @@ class OrderRequestController extends GetxController {
}
void addCustomStartIcon() async {
// Create the marker with the resized image
ImageConfiguration config = ImageConfiguration(
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
ImageConfiguration config = const ImageConfiguration(size: Size(30, 30));
BitmapDescriptor.asset(
config,
'assets/images/A.png',
@@ -131,8 +149,7 @@ class OrderRequestController extends GetxController {
}
void addCustomEndIcon() {
ImageConfiguration config = ImageConfiguration(
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
ImageConfiguration config = const ImageConfiguration(size: Size(30, 30));
BitmapDescriptor.asset(
config,
'assets/images/b.png',
@@ -149,8 +166,7 @@ class OrderRequestController extends GetxController {
double mpg = 0;
calculateConsumptionFuel() {
mpg = Get.find<HomeCaptainController>().fuelPrice /
12; //todo in register car add mpg in box
mpg = Get.find<HomeCaptainController>().fuelPrice / 12;
}
bool _timerActive = false;
@@ -161,7 +177,6 @@ class OrderRequestController extends GetxController {
await Future.delayed(const Duration(seconds: 1));
progress = i / duration;
remainingTime = duration - i;
update();
}
if (remainingTime == 0 && _timerActive) {
@@ -181,13 +196,11 @@ class OrderRequestController extends GetxController {
await Future.delayed(const Duration(seconds: 1));
progressSpeed = i / durationSpeed;
remainingTimeSpeed = durationSpeed - i;
update();
}
if (remainingTimeSpeed == 0) {
if (applied == false) {
Get.back();
// refuseOrder(box.read(BoxName.driverID), orderID);
}
}
}
@@ -196,39 +209,23 @@ class OrderRequestController extends GetxController {
orderID,
) async {
await CRUD().postFromDialogue(link: AppLink.addDriverOrder, payload: {
//TODO need review
'driver_id': box.read(BoxName.driverID),
// box.read(BoxName.driverID).toString(),
'order_id': orderID,
'status': 'Refused'
});
await CRUD().post(link: AppLink.updateRides, payload: {
'id': orderID,
// 'rideTimeStart': DateTime.now().toString(),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
if (AppLink.endPoint != AppLink.seferCairoServer) {
CRUD().post(link: '${AppLink.endPoint}/rides/update.php', payload: {
'id': orderID,
// 'rideTimeStart': DateTime.now().toString(),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
}
// applied = true;
// if (box.read(BoxName.gender).toString() != 'Female') {
// sql.insertData({
// 'order_id': orderID,
// 'created_at': DateTime.now().toString(),
// 'driver_id': box.read(BoxName.driverID).toString(),
// }, TableName.driverOrdersRefuse);
// getRefusedOrderByCaptain();
// }
update();
// Get.back();
// Get.offAll(HomeCaptain());
}
addRideToNotificationDriverString(