This commit is contained in:
Hamza-Ayed
2024-02-07 00:41:38 +03:00
parent 2820eceee0
commit 63d954e356
3 changed files with 78 additions and 82 deletions

View File

@@ -5,6 +5,7 @@ import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_polyline_algorithm/google_polyline_algorithm.dart'; import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';
@@ -861,14 +862,12 @@ class MapPassengerController extends GetxController {
Future runEvery30SecondsUntilConditionMet() async { Future runEvery30SecondsUntilConditionMet() async {
// Calculate the duration of the trip in minutes. // Calculate the duration of the trip in minutes.
double tripDurationInMinutes = duration1 / 20; double tripDurationInMinutes = duration1 / 4;
int loopCount = tripDurationInMinutes.ceil(); int loopCount = tripDurationInMinutes.ceil();
// If the trip duration is less than or equal to 50 minutes, then break the loop. // If the trip duration is less than or equal to 50 minutes, then break the loop.
for (var i = 0; i < loopCount; i++) { for (var i = 0; i < loopCount; i++) {
// Wait for 50 seconds. // Wait for 50 seconds.
await Future.delayed(const Duration( await Future.delayed(const Duration(seconds: 4));
seconds:
31)); // Run the `getDriverCarsLocationToPassengerAfterApplied()` function.
await getDriverCarsLocationToPassengerAfterApplied(); await getDriverCarsLocationToPassengerAfterApplied();
reloadMarkerDriverCarsLocationToPassengerAfterApplied(); reloadMarkerDriverCarsLocationToPassengerAfterApplied();
} }
@@ -940,49 +939,48 @@ class MapPassengerController extends GetxController {
// clearPolylineAll(); // clearPolylineAll();
data = []; data = [];
changeCancelRidePageShow(); changeCancelRidePageShow();
if (rideId != '') {
rideConfirm = false;
shouldFetch = false;
isCashConfirmPageShown = false;
isPassengerChosen = false;
isCashSelectedBeforeConfirmRide = false;
isPickerShown = false;
isMarkersShown = false;
haveSteps = false;
isMarkersShown = false;
// totalStepDurations = 0;
timeToPassengerFromDriverAfterApplied = 0;
if (rideId != 'yet') {
await CRUD().post(link: AppLink.updateDriverOrder, payload: { await CRUD().post(link: AppLink.updateDriverOrder, payload: {
"order_id": rideId.toString(), // Convert to String "order_id": rideId.toString(), // Convert to String
"status": 'Cancel' "status": 'Cancel'
}); });
} }
rideConfirm = false;
shouldFetch = false;
isCashConfirmPageShown = false;
isPassengerChosen = false;
isCashSelectedBeforeConfirmRide = false;
isPickerShown = false;
isMarkersShown = false;
haveSteps = false;
isMarkersShown = false;
// totalStepDurations = 0;
timeToPassengerFromDriverAfterApplied = 0;
remainingTime = 0;
update(); update();
} else { } else {
clearPlacesDestination(); clearPlacesDestination();
clearPolyline(); clearPolyline();
data = []; data = [];
isPickerShown = false;
rideConfirm = false;
shouldFetch = false;
isPassengerChosen = false;
haveSteps = false;
isMarkersShown = false;
isCashConfirmPageShown = false;
isCashSelectedBeforeConfirmRide = false;
timeToPassengerFromDriverAfterApplied = 0;
// totalStepDurations = 0;
changeCancelRidePageShow();
clearPolyline();
remainingTime = 0;
await CRUD().post(link: AppLink.updateDriverOrder, payload: { await CRUD().post(link: AppLink.updateDriverOrder, payload: {
"order_id": rideId.toString(), // Convert to String "order_id": rideId.toString(), // Convert to String
"status": 'Cancel' "status": 'Cancel'
}); });
FirebaseMessagesController().sendNotificationToDriverMAP( FirebaseMessagesController().sendNotificationToDriverMAP(
'Cancel Trip', 'Trip Cancelled'.tr, driverToken, []); 'Cancel Trip', 'Trip Cancelled'.tr, driverToken, []);
isPickerShown = false;
rideConfirm = false;
shouldFetch = false;
isCashConfirmPageShown = false;
isPassengerChosen = false;
isCashSelectedBeforeConfirmRide = false;
haveSteps = false;
isMarkersShown = false;
timeToPassengerFromDriverAfterApplied = 0;
changeCancelRidePageShow();
clearPolyline();
remainingTime = 0;
durationTimer = 0;
update(); update();
} }
} }
@@ -1015,7 +1013,7 @@ class MapPassengerController extends GetxController {
if (heightMenuBool == true) { if (heightMenuBool == true) {
getDrawerMenu(); getDrawerMenu();
} }
initilizeGetStorage();
update(); update();
} }
} }
@@ -1389,21 +1387,6 @@ class MapPassengerController extends GetxController {
i++) { i++) {
var carLocation = dataCarsLocationByPassenger['message'][i]; var carLocation = dataCarsLocationByPassenger['message'][i];
// double distance1 = Geolocator.distanceBetween(
// mylocation.latitude,
// mylocation.longitude,
// double.parse(carLocation['latitude']),
// double.parse(carLocation['longitude']),
// );
// if (distance1 < nearestDistance) {
// nearestDistance = distance1;
// // nearestCarLocation = carLocation;
// nearestCar = CarLocation(
// distance: distance1,
// id: carLocation['driver_id'],
// latitude: double.parse(carLocation['latitude']),
// longitude: double.parse(carLocation['longitude']),
// );
// } // }
// isloading = true; // isloading = true;
update(); update();
@@ -1462,6 +1445,33 @@ class MapPassengerController extends GetxController {
//print(nearestCar!.id); //print(nearestCar!.id);
} }
calculateDistanceBetweenPassengerAndDriverBeforecancelRide() async {
// await getDriverCarsLocationToPassengerAfterApplied();
double distance = Geolocator.distanceBetween(
passengerLocation.latitude,
passengerLocation.longitude,
double.parse(datadriverCarsLocationToPassengerAfterApplied['message']
[carsOrder]['latitude']),
double.parse(datadriverCarsLocationToPassengerAfterApplied['message']
[carsOrder]['longitude']));
if (distance > 500) {
cancelRide();
} else {
Get.defaultDialog(
title: 'The Driver Will be in your location soon .'.tr,
middleText: 'The distance less than 500 meter.'.tr,
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () {
Get.back();
},
),
);
// cancel: MyElevatedButton(
// title: 'No.Iwant Cancel Trip.'.tr, onPressed: () {}));
}
}
List<double> headingAngles = []; List<double> headingAngles = [];
late LatLngBounds boundsData; late LatLngBounds boundsData;
@@ -1881,7 +1891,7 @@ class MapPassengerController extends GetxController {
@override @override
void onInit() async { void onInit() async {
// mapAPIKEY = await storage.read(key: BoxName.mapAPIKEY); mapAPIKEY = await storage.read(key: BoxName.mapAPIKEY);
readyWayPoints(); readyWayPoints();
await getLocation(); await getLocation();
await addToken(); await addToken();

View File

@@ -163,8 +163,6 @@ class MainBottomMenuMap extends StatelessWidget {
onPressed: () { onPressed: () {
controller controller
.changeMainBottomMenuMap(); .changeMainBottomMenuMap();
// controller
// .initilizeGetStorage();
}, },
icon: icon:
controller.isMainBottomMenuMap controller.isMainBottomMenuMap

View File

@@ -37,13 +37,14 @@ class TimerToPassengerFromDriver extends StatelessWidget {
'You Can cancel Ride After Captain did not come in the time' 'You Can cancel Ride After Captain did not come in the time'
.tr, .tr,
style: AppStyle.title, style: AppStyle.title,
textAlign: TextAlign.center,
), ),
Stack( Stack(
children: [ children: [
LinearProgressIndicator( LinearProgressIndicator(
backgroundColor: AppColor.accentColor, backgroundColor: AppColor.accentColor,
color: color: controller
controller.timeToPassengerFromDriverAfterApplied < .remainingTimeToPassengerFromDriverAfterApplied <
60 60
? AppColor.redColor ? AppColor.redColor
: AppColor.greenColor, : AppColor.greenColor,
@@ -61,33 +62,20 @@ class TimerToPassengerFromDriver extends StatelessWidget {
) )
], ],
), ),
// controller.remainingTimeToPassengerFromDriverAfterApplied < 60 controller.remainingTimeToPassengerFromDriverAfterApplied < 60
// ? MyElevatedButton( ? MyElevatedButton(
// title: 'If you in Car Now. Press Start The Ride'.tr, title: 'You can cancel trip'.tr,
// onPressed: () async { onPressed: () async {
// //todo start the trip and rest all counter ,start new counter of the trip time
//
// await CRUD() // await CRUD()
// .post(link: AppLink.updateRides, payload: { // .post(link: AppLink.updateRides, payload: {
// 'id': controller.rideId, // 'id': controller.rideId,
// 'rideTimeStart': DateTime.now().toString(), // 'rideTimeStart': DateTime.now().toString(),
// 'status': 'Applied' // 'status': 'Applied'
// }); // });
// controller.driverArrivePassenger(); controller
// // Send notification to driver to alert him that trip is begin .calculateDistanceBetweenPassengerAndDriverBeforecancelRide();
// FirebaseMessagesController() })
// .sendNotificationToAnyWithoutData( : const SizedBox()
// 'BeginTrip',
// box.read(BoxName.name).toString(),
// controller.driverToken.toString(),
// );
// print(controller.driverToken.toString());
// // Get.defaultDialog(
// // title: 'The Ride is Begin'.tr,
// // backgroundColor: AppColor.greenColor,
// // );
// })
// : const SizedBox()
], ],
), ),
), ),