Files
tripz/t dataBounds = []
Hamza-Ayed 87da645ae5 1/27/2
2024-01-30 16:58:23 +02:00

345 lines
19 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
warning: in the working copy of 'linux/flutter/generated_plugin_registrant.cc', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'linux/flutter/generated_plugin_registrant.h', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'linux/flutter/generated_plugins.cmake', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'macos/Flutter/GeneratedPluginRegistrant.swift', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'windows/flutter/generated_plugin_registrant.cc', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'windows/flutter/generated_plugin_registrant.h', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'windows/flutter/generated_plugins.cmake', LF will be replaced by CRLF the next time Git touches it
diff --git a/lib/controller/home/captin/map_driver_controller.dart b/lib/controller/home/captin/map_driver_controller.dart
index 8c72810..34875b4 100644
--- a/lib/controller/home/captin/map_driver_controller.dart
+++ b/lib/controller/home/captin/map_driver_controller.dart
@@ -226,7 +226,7 @@ class MapDriverController extends GetxController {
});
rideIsBeginPassengerTimer();
double pointsSubstraction = 0;
- pointsSubstraction = double.parse(paymentAmount) * -1;
+ pointsSubstraction = double.parse(paymentAmount) * -100;
var res = await CRUD().post(link: AppLink.addDriversWallet, payload: {
'paymentID': 'rideId$rideId',
'amount': (pointsSubstraction).toString(),
@@ -429,7 +429,12 @@ class MapDriverController extends GetxController {
width: 10,
color: AppColor.blueColor,
);
- mapController!.animateCamera(CameraUpdate.newLatLngZoom(myLocation, 14));
+ // final dataBounds = response["routes"][0]["bounds"];
+
+ // updateCameraFromBoundsAfterGetMap(dataBounds);
+
+// Fit the camera to the bounds
+
polyLines.add(polyline);
// rideConfirm = false;
update();
@@ -468,13 +473,31 @@ class MapDriverController extends GetxController {
width: 10,
color: AppColor.redColor,
);
+ // final dataBounds = response["routes"][0]["bounds"];

- polyLinesDestination.add(polyline);
+ // updateCameraFromBoundsAfterGetMap(dataBounds);
+ // polyLinesDestination.add(polyline);
// rideConfirm = false;
update();
}
}

+ void updateCameraFromBoundsAfterGetMap(dynamic response) {
+ final bounds = response["routes"][0]["bounds"];
+ LatLng northeast =
+ LatLng(bounds['northeast']['lat'], bounds['northeast']['lng']);
+ LatLng southwest =
+ LatLng(bounds['southwest']['lat'], bounds['southwest']['lng']);
+
+// Create the LatLngBounds object
+ LatLngBounds boundsData =
+ LatLngBounds(northeast: northeast, southwest: southwest);
+
+// Fit the camera to the bounds
+ var cameraUpdate = CameraUpdate.newLatLngBounds(boundsData, 140);
+ mapController!.animateCamera(cameraUpdate);
+ }
+
void changePassengerInfoWindow() {
isPassengerInfoWindow = !isPassengerInfoWindow;
passengerInfoWindow = isPassengerInfoWindow == true ? 200 : 0;
diff --git a/lib/controller/home/map_passenger_controller.dart b/lib/controller/home/map_passenger_controller.dart
index a2d4712..d4adf6f 100644
--- a/lib/controller/home/map_passenger_controller.dart
+++ b/lib/controller/home/map_passenger_controller.dart
@@ -186,6 +186,7 @@ class MapPassengerController extends GetxController {
late double cost = 0;
late double distance = 0;
late double duration = 0;
+ List dataBounds = [];

late Duration durationToAdd;
late DateTime newTime = DateTime.now();
@@ -218,8 +219,9 @@ class MapPassengerController extends GetxController {
durationToRide = 0;
distanceOfDestnation = 0;
wayPointSheetHeight = 0;
- for (var i = 0; i < Get.find<WayPointController>().wayPoints.length; i++) {
- if (placesCoordinate[i + 1].toString() != '') {
+ for (var i = 0; i < placesCoordinate.length; i++) {
+ if (placesCoordinate[i + 1].toString() != '' ||
+ placesCoordinate[i + 1].toString() != null) {
await getMapPoints(
placesCoordinate[i].toString(),
placesCoordinate[i + 1].toString(),
@@ -227,7 +229,7 @@ class MapPassengerController extends GetxController {
);
}
}
- updateCameraForDistanceAfterGetMap();
+ // updateCameraForDistanceAfterGetMap();
// isWayPointStopsSheet = false;
if (haveSteps) {
String latestWaypoint =
@@ -378,13 +380,9 @@ class MapPassengerController extends GetxController {
}

void sendSMS(String to) async {
- // Get the driver's phone number.
- String driverPhone =
- dataCarsLocationByPassenger['message'][carsOrder]['phone'].toString();
-
// Format the message.
String message =
- 'Hi! This is ${box.read(BoxName.name)}. I am using ${box.read(AppInformation.appName)} to ride with ${dataCarsLocationByPassenger['message'][carsOrder]['first_name'].toString()} as the driver. ${dataCarsLocationByPassenger['message'][carsOrder]['first_name'].toString()} is driving a ${dataCarsLocationByPassenger['message'][carsOrder]['model'].toString()} with license plate ${dataCarsLocationByPassenger['message'][carsOrder]['license_plate'].toString()}. I am currently located at $passengerLocation. If you need to reach me, please contact the driver directly at $driverPhone.';
+ 'Hi! This is ${box.read(BoxName.name)}.\n I am using ${box.read(AppInformation.appName)} to ride with $firstName as the driver. $firstName \nis driving a $model\n with license plate $licensePlate.\n I am currently located at $passengerLocation.\n If you need to reach me, please contact the driver directly at\n\n $driverPhone .';

// Launch the URL to send the SMS.
launchCommunication('sms', to, message);
@@ -392,12 +390,10 @@ class MapPassengerController extends GetxController {

void sendWhatsapp(String to) async {
// Get the driver's phone number.
- String driverPhone =
- dataCarsLocationByPassenger['message'][carsOrder]['phone'].toString();

// Format the message.
String message =
- 'Hi! This is ${box.read(BoxName.name)}.\n I am using ${box.read(AppInformation.appName)} to ride with ${dataCarsLocationByPassenger['message'][carsOrder]['first_name'].toString()} as the driver. ${dataCarsLocationByPassenger['message'][carsOrder]['first_name'].toString()} \nis driving a ${dataCarsLocationByPassenger['message'][carsOrder]['model'].toString()}\n with license plate ${dataCarsLocationByPassenger['message'][carsOrder]['license_plate'].toString()}.\n I am currently located at $passengerLocation.\n If you need to reach me, please contact the driver directly at\n\n $driverPhone.';
+ 'Hi! This is ${box.read(BoxName.name)}.\n I am using ${box.read(AppInformation.appName)} to ride with $firstName as the driver. $firstName \nis driving a $model\n with license plate $licensePlate.\n I am currently located at $passengerLocation.\n If you need to reach me, please contact the driver directly at\n\n $driverPhone .';

// Launch the URL to send the SMS.
launchCommunication('whatsapp', to, message);
@@ -444,6 +440,44 @@ class MapPassengerController extends GetxController {
}
}

+ // void startTimerToPassengerFromDriverAfterApplied() async {
+ // for (int i = 0; i <= timeToPassengerFromDriverAfterApplied; i++) {
+ // await Future.delayed(const Duration(seconds: 1));
+ // progressTimerToPassengerFromDriverAfterApplied =
+ // i / timeToPassengerFromDriverAfterApplied;
+ // remainingTimeToPassengerFromDriverAfterApplied =
+ // timeToPassengerFromDriverAfterApplied - i;
+
+ // var response = await CRUD().post(
+ // link: AppLink.addAdminUser, ////////change to nnew endpoint
+ // payload: {
+ // 'ride_id': rideId,
+ // 'time_to_passenger_from_driver_after_applied':
+ // timeToPassengerFromDriverAfterApplied,
+ // });
+
+ // if (response.statusCode == 200) {
+ // // Update progress and remaining time
+ // int minutes =
+ // (remainingTimeToPassengerFromDriverAfterApplied / 60).floor();
+ // int seconds = remainingTimeToPassengerFromDriverAfterApplied % 60;
+ // stringRemainingTimeToPassenger =
+ // '$minutes:${seconds.toString().padLeft(2, '0')}';
+ // update();
+
+ // if (remainingTimeToPassengerFromDriverAfterApplied < 69) {
+ // if (rideTimerBegin == false) {
+ // getBeginRideFromDriver();
+ // }
+ // }
+ // } else {
+ // // Handle error
+ // print(
+ // 'Error updating time to passenger: ${response.statusCode} ${response.reasonPhrase} ${response.body}');
+ // }
+ // }
+ // }
+
// Create a StreamController to manage the timer values
final timerController = StreamController<int>();

@@ -579,10 +613,24 @@ class MapPassengerController extends GetxController {
update();
}

+ late String driverPhone;
+ late String firstName;
+ late String model;
+ late String licensePlate;
changeConfirmRide() async {
if (dataCarsLocationByPassenger != 'failure') {
driverToken =
dataCarsLocationByPassenger['message'][carsOrder]['token'].toString();
+ driverPhone =
+ dataCarsLocationByPassenger['message'][carsOrder]['phone'].toString();
+ firstName = dataCarsLocationByPassenger['message'][carsOrder]
+ ['first_name']
+ .toString();
+ model =
+ dataCarsLocationByPassenger['message'][carsOrder]['model'].toString();
+ licensePlate = dataCarsLocationByPassenger['message'][carsOrder]
+ ['license_plate']
+ .toString();
PaymentController paymentController = Get.find<PaymentController>();
rideConfirm = true;
shouldFetch = true;
@@ -617,9 +665,9 @@ class MapPassengerController extends GetxController {
List<String> body = [
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
- totalPassenger.toString(),
+ totalPassenger.toStringAsFixed(2),
totalDriver.toString(),
- duration.toString(),
+ Duration(seconds: durationToRide).toString(),
distance.toString(),
dataCarsLocationByPassenger['message'][carsOrder]['driver_id']
.toString(),
@@ -1442,23 +1490,29 @@ class MapPassengerController extends GetxController {
double lng = points[i][1].toDouble();
polylineCoordinates.add(LatLng(lat, lng));
}
+ newStartPointLocation = LatLng(
+ data[0]["start_location"]['lat'], data[0]["start_location"]['lng']);
// Define the northeast and southwest coordinates
final bounds = response["routes"][0]["bounds"];
-
LatLng northeast =
LatLng(bounds['northeast']['lat'], bounds['northeast']['lng']);
LatLng southwest =
LatLng(bounds['southwest']['lat'], bounds['southwest']['lng']);

- // Create the LatLngBounds object
- boundsData = LatLngBounds(northeast: northeast, southwest: southwest);
+// Create the LatLngBounds object
+ LatLngBounds boundsData =
+ LatLngBounds(northeast: northeast, southwest: southwest);
+
+// Fit the camera to the bounds
+ var cameraUpdate = CameraUpdate.newLatLngBounds(boundsData, 130);
+ mapController!.animateCamera(cameraUpdate);

// Calculate the zoom level based on the distance and screen size

// getDistanceFromText(data[0]['distance']['text']);
double distanceOfTrip = (data[0]['distance']['value']) / 1000;
distance = distanceOfTrip;
- updateCameraForDistanceAfterGetMap();
+ // updateCameraForDistanceAfterGetMap();

if (polyLines.isNotEmpty) {
clearPolyline();
@@ -1506,15 +1560,6 @@ class MapPassengerController extends GetxController {
polylineCoordinatesPointsAll[index].add(LatLng(lat, lng));
}
// Define the northeast and southwest coordinates
- final bounds = response["routes"][0]["bounds"];
-
- LatLng northeast =
- LatLng(bounds['northeast']['lat'], bounds['northeast']['lng']);
- LatLng southwest =
- LatLng(bounds['southwest']['lat'], bounds['southwest']['lng']);
-
- // Create the LatLngBounds object
- boundsData = LatLngBounds(northeast: northeast, southwest: southwest);

if (polyLines.isNotEmpty) {
// clearPolyline();
@@ -1533,6 +1578,22 @@ class MapPassengerController extends GetxController {
}
}

+ void updateCameraFromBoundsAfterGetMap(dynamic response) {
+ final bounds = response["routes"][0]["bounds"];
+ LatLng northeast =
+ LatLng(bounds['northeast']['lat'], bounds['northeast']['lng']);
+ LatLng southwest =
+ LatLng(bounds['southwest']['lat'], bounds['southwest']['lng']);
+
+// Create the LatLngBounds object
+ LatLngBounds boundsData =
+ LatLngBounds(northeast: northeast, southwest: southwest);
+
+// Fit the camera to the bounds
+ var cameraUpdate = CameraUpdate.newLatLngBounds(boundsData, 140);
+ mapController!.animateCamera(cameraUpdate);
+ }
+
updateCameraForDistanceAfterGetMap() {
if (distance <= 5) {
mapController!
diff --git a/lib/views/home/Captin/mapDriverWidgets/driver_end_ride_bar.dart b/lib/views/home/Captin/mapDriverWidgets/driver_end_ride_bar.dart
index f37bea3..eb5e3a0 100644
--- a/lib/views/home/Captin/mapDriverWidgets/driver_end_ride_bar.dart
+++ b/lib/views/home/Captin/mapDriverWidgets/driver_end_ride_bar.dart
@@ -20,7 +20,7 @@ GetBuilder<MapDriverController> driverEndRideBar() {
child: Column(
children: [
Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
+ mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: [
@@ -31,15 +31,6 @@ GetBuilder<MapDriverController> driverEndRideBar() {
),
],
),
- mapDriverController.remainingTimeTimerRideBegin < 60
- ? MyElevatedButton(
- title: 'End Ride'.tr,
- onPressed: () {
- mapDriverController.finishRideFromDriver();
- },
- kolor: AppColor.redColor,
- )
- : const SizedBox(),
Column(
children: [
const Icon(Icons.timelapse),
@@ -48,8 +39,30 @@ GetBuilder<MapDriverController> driverEndRideBar() {
style: AppStyle.title),
],
),
+ Column(
+ children: [
+ const Icon(Icons.money_sharp),
+ Text(
+ '${mapDriverController.paymentAmount} ${'\$'.tr}',
+ style: AppStyle.title),
+ ],
+ ),
],
),
+ mapDriverController.remainingTimeTimerRideBegin < 60
+ ? Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ MyElevatedButton(
+ title: 'End Ride'.tr,
+ onPressed: () {
+ mapDriverController.finishRideFromDriver();
+ },
+ kolor: AppColor.redColor,
+ ),
+ ],
+ )
+ : const SizedBox(),
Stack(
children: [
LinearProgressIndicator(