From 63d954e356f7d74a6644fd83fcba9cd0de568c48 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Wed, 7 Feb 2024 00:41:38 +0300 Subject: [PATCH] 2/6/5 --- .../home/map_passenger_controller.dart | 106 ++++++++++-------- .../map_widget.dart/main_bottom_Menu_map.dart | 2 - .../timer_to_passenger_from_driver.dart | 52 ++++----- 3 files changed, 78 insertions(+), 82 deletions(-) diff --git a/lib/controller/home/map_passenger_controller.dart b/lib/controller/home/map_passenger_controller.dart index 91475ca..1acbcab 100644 --- a/lib/controller/home/map_passenger_controller.dart +++ b/lib/controller/home/map_passenger_controller.dart @@ -5,6 +5,7 @@ import 'dart:math' as math; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:geolocator/geolocator.dart'; import 'package:get/get.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_polyline_algorithm/google_polyline_algorithm.dart'; @@ -861,14 +862,12 @@ class MapPassengerController extends GetxController { Future runEvery30SecondsUntilConditionMet() async { // Calculate the duration of the trip in minutes. - double tripDurationInMinutes = duration1 / 20; + double tripDurationInMinutes = duration1 / 4; int loopCount = tripDurationInMinutes.ceil(); // If the trip duration is less than or equal to 50 minutes, then break the loop. for (var i = 0; i < loopCount; i++) { // Wait for 50 seconds. - await Future.delayed(const Duration( - seconds: - 31)); // Run the `getDriverCarsLocationToPassengerAfterApplied()` function. + await Future.delayed(const Duration(seconds: 4)); await getDriverCarsLocationToPassengerAfterApplied(); reloadMarkerDriverCarsLocationToPassengerAfterApplied(); } @@ -940,49 +939,48 @@ class MapPassengerController extends GetxController { // clearPolylineAll(); data = []; changeCancelRidePageShow(); - - 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') { + if (rideId != '') { await CRUD().post(link: AppLink.updateDriverOrder, payload: { "order_id": rideId.toString(), // Convert to String "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(); } else { clearPlacesDestination(); clearPolyline(); 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: { "order_id": rideId.toString(), // Convert to String "status": 'Cancel' }); FirebaseMessagesController().sendNotificationToDriverMAP( '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(); } } @@ -1015,7 +1013,7 @@ class MapPassengerController extends GetxController { if (heightMenuBool == true) { getDrawerMenu(); } - + initilizeGetStorage(); update(); } } @@ -1389,21 +1387,6 @@ class MapPassengerController extends GetxController { 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; update(); @@ -1462,6 +1445,33 @@ class MapPassengerController extends GetxController { //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 headingAngles = []; late LatLngBounds boundsData; @@ -1881,7 +1891,7 @@ class MapPassengerController extends GetxController { @override void onInit() async { - // mapAPIKEY = await storage.read(key: BoxName.mapAPIKEY); + mapAPIKEY = await storage.read(key: BoxName.mapAPIKEY); readyWayPoints(); await getLocation(); await addToken(); diff --git a/lib/views/home/map_widget.dart/main_bottom_Menu_map.dart b/lib/views/home/map_widget.dart/main_bottom_Menu_map.dart index 25842a5..8d508d7 100644 --- a/lib/views/home/map_widget.dart/main_bottom_Menu_map.dart +++ b/lib/views/home/map_widget.dart/main_bottom_Menu_map.dart @@ -163,8 +163,6 @@ class MainBottomMenuMap extends StatelessWidget { onPressed: () { controller .changeMainBottomMenuMap(); - // controller - // .initilizeGetStorage(); }, icon: controller.isMainBottomMenuMap diff --git a/lib/views/home/map_widget.dart/timer_to_passenger_from_driver.dart b/lib/views/home/map_widget.dart/timer_to_passenger_from_driver.dart index 99dbaf1..29b7591 100644 --- a/lib/views/home/map_widget.dart/timer_to_passenger_from_driver.dart +++ b/lib/views/home/map_widget.dart/timer_to_passenger_from_driver.dart @@ -37,16 +37,17 @@ class TimerToPassengerFromDriver extends StatelessWidget { 'You Can cancel Ride After Captain did not come in the time' .tr, style: AppStyle.title, + textAlign: TextAlign.center, ), Stack( children: [ LinearProgressIndicator( backgroundColor: AppColor.accentColor, - color: - controller.timeToPassengerFromDriverAfterApplied < - 60 - ? AppColor.redColor - : AppColor.greenColor, + color: controller + .remainingTimeToPassengerFromDriverAfterApplied < + 60 + ? AppColor.redColor + : AppColor.greenColor, minHeight: 50, borderRadius: BorderRadius.circular(15), value: controller @@ -61,33 +62,20 @@ class TimerToPassengerFromDriver extends StatelessWidget { ) ], ), - // controller.remainingTimeToPassengerFromDriverAfterApplied < 60 - // ? MyElevatedButton( - // title: 'If you in Car Now. Press Start The Ride'.tr, - // onPressed: () async { - // //todo start the trip and rest all counter ,start new counter of the trip time - // - // await CRUD() - // .post(link: AppLink.updateRides, payload: { - // 'id': controller.rideId, - // 'rideTimeStart': DateTime.now().toString(), - // 'status': 'Applied' - // }); - // controller.driverArrivePassenger(); - // // Send notification to driver to alert him that trip is begin - // FirebaseMessagesController() - // .sendNotificationToAnyWithoutData( - // '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() + controller.remainingTimeToPassengerFromDriverAfterApplied < 60 + ? MyElevatedButton( + title: 'You can cancel trip'.tr, + onPressed: () async { + // await CRUD() + // .post(link: AppLink.updateRides, payload: { + // 'id': controller.rideId, + // 'rideTimeStart': DateTime.now().toString(), + // 'status': 'Applied' + // }); + controller + .calculateDistanceBetweenPassengerAndDriverBeforecancelRide(); + }) + : const SizedBox() ], ), ),