From 7c627d5182b0877170e5fe96c3e28295cfd641a3 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sun, 11 Feb 2024 00:24:07 +0300 Subject: [PATCH] 2/10/1 --- lib/controller/firebase/firbase_messge.dart | 209 ++++++++++-------- .../home/captin/map_driver_controller.dart | 54 ++++- .../home/map_passenger_controller.dart | 5 +- .../passenger_info_window.dart | 32 ++- .../map_widget.dart/left_main_menu_icons.dart | 3 +- .../timer_to_passenger_from_driver.dart | 2 +- 6 files changed, 201 insertions(+), 104 deletions(-) diff --git a/lib/controller/firebase/firbase_messge.dart b/lib/controller/firebase/firbase_messge.dart index ca6edae..fa45e15 100644 --- a/lib/controller/firebase/firbase_messge.dart +++ b/lib/controller/firebase/firbase_messge.dart @@ -17,6 +17,7 @@ import '../../constant/style.dart'; import '../../main.dart'; import '../../views/Rate/rate_captain.dart'; import '../../views/home/Captin/home_captain/home_captin.dart'; +import '../../views/home/map_page_passenger.dart'; import '../../views/home/profile/promos_passenger_page.dart'; import '../../views/home/Captin/orderCaptin/order_request_page.dart'; import '../home/map_passenger_controller.dart'; @@ -146,36 +147,11 @@ class FirebaseMessagesController extends GetxController { var myList = jsonDecode(passengerList) as List; driverID = myList[2].toString(); - Get.snackbar( - 'Captain Applied the Ride for You'.tr, - 'message', - colorText: AppColor.greenColor, - duration: const Duration(seconds: 11), - snackPosition: SnackPosition.TOP, - titleText: Text( - 'Applied'.tr, - style: const TextStyle(color: AppColor.redColor), - ), - messageText: Text( - 'Captain Applied the Ride for You'.tr, - style: AppStyle.title, - ), - icon: const Icon(Icons.approval), - shouldIconPulse: true, - margin: const EdgeInsets.all(16), - padding: const EdgeInsets.all(16), - ); + driverAppliedTripSnakBar(); } else if (message.notification!.title! == 'Promo') { Get.to(const PromosPassengerPage()); } else if (message.notification!.title == 'Cancel Trip') { - Get.defaultDialog( - title: 'Passenger Cancel Trip'.tr, - middleText: '', - confirm: MyElevatedButton( - title: 'Ok'.tr, - onPressed: () { - Get.offAll(HomeCaptain()); - })); + cancelTripDialog(); } else if (message.notification!.title! == 'DriverIsGoingToPassenger') { Get.snackbar('Driver is Going To Passenger', '', backgroundColor: AppColor.greenColor); @@ -187,87 +163,134 @@ class FirebaseMessagesController extends GetxController { backgroundColor: AppColor.greenColor); update(); } else if (message.notification!.title! == 'Hi ,I Arrive your site') { - Get.defaultDialog( - barrierDismissible: false, - title: 'Hi ,I Arrive your site'.tr, - middleText: 'Please go to Car Driver'.tr, - confirm: MyElevatedButton( - title: 'Ok I will go now.'.tr, - onPressed: () { - FirebaseMessagesController().sendNotificationToPassengerToken( - 'Hi ,I will go now'.tr, - 'I will go now'.tr, - Get.find().driverToken, []); - Get.back(); - })); + driverArrivePassengerDialoge(); update(); - } else if (message.notification!.title!.contains('Driver Finish Trip')) { + } else if (message.notification!.title! == 'Driver Finish Trip') { var myListString = message.data['passengerList']; var driverList = jsonDecode(myListString) as List; if (Get.find().isCashChecked == false && Get.find().isWalletChecked == true) { - Get.defaultDialog( - title: 'Driver Finish Trip'.tr, - content: DriverTipWidget(), - confirm: MyElevatedButton( - title: 'Yes'.tr, - onPressed: () async { - var tip = (Get.find().totalPassenger) * - (double.parse(box.read(BoxName.tipPercentage.toString()))); - var res = await CRUD().post(link: AppLink.addTips, payload: { - 'passengerID': box.read(BoxName.passengerID), - 'driverID': driverList[0].toString(), - 'rideID': driverList[1].toString(), - 'tipAmount': tip.toString(), - }); - await CRUD().post(link: AppLink.addPassengersWallet, payload: { - 'passenger_id': box.read(BoxName.passengerID).toString(), - 'balance': ((-1) * tip).toString() - }); - - await CRUD() - .post(link: AppLink.addDriversWalletPoints, payload: { - 'driverID': driverList[0].toString(), - 'paymentID': - '${Get.find().rideId}tip', - 'amount': (tip * 100).toString(), - 'paymentMethod': 'visa-tip', - }); - - if (res != 'failure') { - FirebaseMessagesController().sendNotificationToAnyWithoutData( - 'You Have Tips', - '${tip.toString()}\$ tips\nTotal is ${tip + (Get.find().totalPassenger)}', - driverList[2].toString(), - ); - } - Get.to(() => RateDriverFromPassenger(), arguments: { - 'driverId': driverList[0].toString(), - 'rideId': driverList[1].toString(), - }); - }, - kolor: AppColor.greenColor, - ), - cancel: MyElevatedButton( - title: 'No,I want'.tr, - onPressed: () { - Get.to(() => RateDriverFromPassenger(), arguments: { - 'driverId': driverList[0].toString(), - 'rideId': driverList[1].toString(), - }); - }, - kolor: AppColor.redColor, - )); + driverFinishTripDialoge(driverList); } else { Get.to(() => RateDriverFromPassenger(), arguments: { 'driverId': driverList[0].toString(), 'rideId': driverList[1].toString(), }); } + } else if (message.notification!.title! == 'Driver Cancel Your Trip') { + // Get.snackbar( + // 'You will be pay the cost to driver or we will get it from you on next trip' + // .tr, + // 'message', + // backgroundColor: AppColor.redColor); + Get.find().restCounter(); + Get.offAll(const MapPagePassenger()); } } + SnackbarController driverAppliedTripSnakBar() { + return Get.snackbar( + 'Driver Applied the Ride for You'.tr, + 'message', + colorText: AppColor.greenColor, + duration: const Duration(seconds: 3), + snackPosition: SnackPosition.TOP, + titleText: Text( + 'Applied'.tr, + style: const TextStyle(color: AppColor.redColor), + ), + messageText: Text( + 'Driver Applied the Ride for You'.tr, + style: AppStyle.title, + ), + icon: const Icon(Icons.approval), + shouldIconPulse: true, + margin: const EdgeInsets.all(16), + padding: const EdgeInsets.all(16), + ); + } + + Future cancelTripDialog() { + return Get.defaultDialog( + title: 'Passenger Cancel Trip'.tr, + middleText: '', + confirm: MyElevatedButton( + title: 'Ok'.tr, + onPressed: () { + Get.offAll(HomeCaptain()); + })); + } + + Future driverArrivePassengerDialoge() { + return Get.defaultDialog( + barrierDismissible: false, + title: 'Hi ,I Arrive your site'.tr, + middleText: 'Please go to Car Driver'.tr, + confirm: MyElevatedButton( + title: 'Ok I will go now.'.tr, + onPressed: () { + FirebaseMessagesController().sendNotificationToPassengerToken( + 'Hi ,I will go now'.tr, + 'I will go now'.tr, + Get.find().driverToken, []); + Get.back(); + })); + } + + Future driverFinishTripDialoge(List driverList) { + return Get.defaultDialog( + title: 'Driver Finish Trip'.tr, + content: const DriverTipWidget(), + confirm: MyElevatedButton( + title: 'Yes'.tr, + onPressed: () async { + var tip = (Get.find().totalPassenger) * + (double.parse(box.read(BoxName.tipPercentage.toString()))); + var res = await CRUD().post(link: AppLink.addTips, payload: { + 'passengerID': box.read(BoxName.passengerID), + 'driverID': driverList[0].toString(), + 'rideID': driverList[1].toString(), + 'tipAmount': tip.toString(), + }); + await CRUD().post(link: AppLink.addPassengersWallet, payload: { + 'passenger_id': box.read(BoxName.passengerID).toString(), + 'balance': ((-1) * tip).toString() + }); + + await CRUD().post(link: AppLink.addDriversWalletPoints, payload: { + 'driverID': driverList[0].toString(), + 'paymentID': '${Get.find().rideId}tip', + 'amount': (tip * 100).toString(), + 'paymentMethod': 'visa-tip', + }); + + if (res != 'failure') { + FirebaseMessagesController().sendNotificationToAnyWithoutData( + 'You Have Tips', + '${tip.toString()}\$ tips\nTotal is ${tip + (Get.find().totalPassenger)}', + driverList[2].toString(), + ); + } + Get.to(() => RateDriverFromPassenger(), arguments: { + 'driverId': driverList[0].toString(), + 'rideId': driverList[1].toString(), + }); + }, + kolor: AppColor.greenColor, + ), + cancel: MyElevatedButton( + title: 'No,I want'.tr, + onPressed: () { + Get.to(() => RateDriverFromPassenger(), arguments: { + 'driverId': driverList[0].toString(), + 'rideId': driverList[1].toString(), + }); + }, + kolor: AppColor.redColor, + )); + } + void sendNotificationAll(String title, body) async { // Get the token you want to subtract. String token = box.read(BoxName.tokenFCM); diff --git a/lib/controller/home/captin/map_driver_controller.dart b/lib/controller/home/captin/map_driver_controller.dart index f09c5de..d2c4cce 100644 --- a/lib/controller/home/captin/map_driver_controller.dart +++ b/lib/controller/home/captin/map_driver_controller.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:math'; import 'package:flutter/material.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'; @@ -63,7 +64,7 @@ class MapDriverController extends GetxController { bool isPassengerInfoWindow = false; bool isBtnRideBegin = false; bool isArrivedSend = true; - bool isBtnPassengerWait = false; + bool isdriverWaitTimeEnd = false; bool isRideFinished = false; bool isRideStarted = false; double passengerInfoWindow = Get.height * .35; @@ -211,11 +212,11 @@ class MapDriverController extends GetxController { progressInPassengerLocationFromDriver = i / (timeWaitingPassenger * 60); remainingTimeInPassengerLocatioWait = (timeWaitingPassenger * 60) - i; if (remainingTimeInPassengerLocatioWait == 0) { - isBtnPassengerWait = true; - print(isBtnPassengerWait); + isdriverWaitTimeEnd = true; + print(isdriverWaitTimeEnd); update(); } - print(isBtnPassengerWait); + print(isdriverWaitTimeEnd); print( 'remainingTimeInPassengerLocatioWait $remainingTimeInPassengerLocatioWait'); @@ -282,6 +283,48 @@ class MapDriverController extends GetxController { // 'RideIsBegin', box.read(BoxName.name).toString(), tokenPassenger); } + addWaittingTimeCostFromPassengerToDriverWallet() async { + double distance2 = Geolocator.distanceBetween( + latLngpassengerLocation.latitude, + latLngpassengerLocation.longitude, + Get.find().myLocation.latitude, + Get.find().myLocation.longitude, + ); + if (distance2 > 80) { + Get.defaultDialog( + title: 'Your are far from passenger location'.tr, + middleText: + 'go to your passenger location before\nPassenger cancel trip'.tr, + confirm: MyElevatedButton( + title: 'Ok', + onPressed: () { + Get.back(); + })); + } else { + double cost = + (distanceBetweenDriverAndPassengerWhenConfirm * .08) + (5 * .06); + var res = await CRUD().post(link: AppLink.addDriverpayment, payload: { + 'rideId': rideId, + 'amount': cost.toString(), + 'payment_method': 'wait-cancel', + 'passengerID': passengerId, + 'driverID': box.read(BoxName.driverID).toString(), + }); + if (res != 'failure') { + Get.snackbar( + 'You will get cost of your work for this trip'.tr, + 'you gain $cost \$ in your wallet', + backgroundColor: AppColor.deepPurpleAccent, + ); + } + await CRUD().post(link: AppLink.addPassengersWallet, payload: { + 'passenger_id': passengerId, + 'balance': (cost * -1).toString() + }); + Get.offAll(HomeCaptain()); + } + } + void finishRideFromDriver() async { isRideFinished = true; isRideStarted = false; @@ -436,6 +479,7 @@ class MapDriverController extends GetxController { }); } + double distanceBetweenDriverAndPassengerWhenConfirm = 0; getMap(String origin, destination) async { isLoading = false; @@ -447,6 +491,8 @@ class MapDriverController extends GetxController { var response = await CRUD().getGoogleApi(link: url, payload: {}); data = response['routes'][0]['legs']; print(data); + distanceBetweenDriverAndPassengerWhenConfirm = + (data[0]['distance']['value']) / 1000; final points = decodePolyline(response["routes"][0]["overview_polyline"]["points"]); for (int i = 0; i < points.length; i++) { diff --git a/lib/controller/home/map_passenger_controller.dart b/lib/controller/home/map_passenger_controller.dart index ac04713..52b0185 100644 --- a/lib/controller/home/map_passenger_controller.dart +++ b/lib/controller/home/map_passenger_controller.dart @@ -650,6 +650,7 @@ class MapPassengerController extends GetxController { late String licensePlate; changeConfirmRide() async { await getCarsLocationByPassenger(); + await getNearestDriverByPassengerLocation(); if (dataCarsLocationByPassenger != 'failure') { driverToken = @@ -1423,7 +1424,7 @@ class MapPassengerController extends GetxController { String distanceByPassenger = ''; late Duration durationFromDriverToPassenger; - void getNearestDriverByPassengerLocation() async { + getNearestDriverByPassengerLocation() async { if (polyLines.isEmpty || data.isEmpty) { if (rideConfirm == false) { double nearestDistance = double.infinity; @@ -1493,7 +1494,7 @@ class MapPassengerController extends GetxController { } calculateDistanceBetweenPassengerAndDriverBeforecancelRide() async { - // await getDriverCarsLocationToPassengerAfterApplied(); + await getDriverCarsLocationToPassengerAfterApplied(); double distance = Geolocator.distanceBetween( passengerLocation.latitude, passengerLocation.longitude, diff --git a/lib/views/home/Captin/mapDriverWidgets/passenger_info_window.dart b/lib/views/home/Captin/mapDriverWidgets/passenger_info_window.dart index 88ff13f..1e90609 100644 --- a/lib/views/home/Captin/mapDriverWidgets/passenger_info_window.dart +++ b/lib/views/home/Captin/mapDriverWidgets/passenger_info_window.dart @@ -4,6 +4,7 @@ import 'package:flutter_font_icons/flutter_font_icons.dart'; import 'package:get/get.dart'; import 'package:ride/constant/box_name.dart'; import 'package:ride/constant/colors.dart'; +import 'package:ride/constant/info.dart'; import 'package:ride/controller/firebase/firbase_messge.dart'; import 'package:ride/controller/home/captin/map_driver_controller.dart'; import 'package:ride/main.dart'; @@ -217,11 +218,13 @@ class PassengerInfoWindow extends StatelessWidget { controller.isArrivedSend = false; }) - : const SizedBox(), + : const SizedBox() ], ), controller.remainingTimeInPassengerLocatioWait < - 300 + 300 && + controller.remainingTimeInPassengerLocatioWait != + 0 ? Stack( children: [ LinearProgressIndicator( @@ -249,7 +252,30 @@ class PassengerInfoWindow extends StatelessWidget { ) ], ) - : const SizedBox(), + : controller.isdriverWaitTimeEnd + ? MyElevatedButton( + title: + 'You Can Cancel Trip And get Cost of Trip From ${AppInformation.appName}' + .tr, + kolor: AppColor + .deepPurpleAccent, + onPressed: () async { + FirebaseMessagesController() + .sendNotificationToPassengerToken( + 'Driver Cancel Your Trip' + .tr, + 'You will be pay the cost to driver or we will get it from you on next trip' + .tr, + controller + .tokenPassenger, + []); + await controller + .addWaittingTimeCostFromPassengerToDriverWallet(); + controller + .isdriverWaitTimeEnd = + false; + }) + : const SizedBox(), ], ), ], diff --git a/lib/views/home/map_widget.dart/left_main_menu_icons.dart b/lib/views/home/map_widget.dart/left_main_menu_icons.dart index 728d49a..b57f8aa 100644 --- a/lib/views/home/map_widget.dart/left_main_menu_icons.dart +++ b/lib/views/home/map_widget.dart/left_main_menu_icons.dart @@ -90,7 +90,8 @@ GetBuilder leftMainMenuIcons() { borderRadius: BorderRadius.circular(15)), child: IconButton( onPressed: () { - textToSpeechController.speakText('''hello this is hamza'''); + textToSpeechController.speakText( + '''hello this is ${box.read(BoxName.name)}'''); }, icon: const Icon( Icons.voice_chat, 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 29b7591..246fc73 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 @@ -72,7 +72,7 @@ class TimerToPassengerFromDriver extends StatelessWidget { // 'rideTimeStart': DateTime.now().toString(), // 'status': 'Applied' // }); - controller + await controller .calculateDistanceBetweenPassengerAndDriverBeforecancelRide(); }) : const SizedBox()