This commit is contained in:
Hamza-Ayed
2024-02-07 21:21:32 +03:00
parent 42c7463181
commit 57d0560a8c
13 changed files with 339 additions and 55 deletions

View File

@@ -6,6 +6,7 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:ride/controller/functions/crud.dart';
import 'package:ride/controller/functions/toast.dart';
import 'package:ride/views/widgets/elevated_btn.dart';
import '../../constant/api_key.dart';
@@ -183,33 +184,56 @@ class FirebaseMessagesController extends GetxController {
// MapPassengerController mapController = Get.put(MapPassengerController());
Get.snackbar('RideIsBegin', '', backgroundColor: AppColor.greenColor);
// mapController.driverArrivePassenger();
update();
} else if (message.notification!.title!.contains('Hi ,I will go now')) {
// MapPassengerController mapController = Get.put(MapPassengerController());
Get.snackbar('Hi ,I will go now', '',
backgroundColor: AppColor.greenColor);
// mapController.driverArrivePassenger();
update();
} else if (message.notification!.title!
.contains('Hi ,I Arrive your site')) {
// MapPassengerController mapController = Get.put(MapPassengerController());
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<MapPassengerController>().driverToken, []);
Get.back();
}));
update();
} else if (message.notification!.title!.contains('Driver Finish Trip')) {
var myListString = message.data['passengerList'];
var driverList = jsonDecode(myListString) as List<dynamic>;
Get.defaultDialog(
title: 'Driver Finish Trip'.tr,
content: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Your fee is ${Get.find<MapPassengerController>().totalPassenger.toStringAsFixed(2)}'),
Text('Do you want to pay Tips for this Driver'.tr)
],
),
content: DriverTipWidget(),
confirm: MyElevatedButton(
title: 'Yes'.tr,
onPressed: () async {
var tip = (Get.find<MapPassengerController>().totalPassenger) *
(double.parse(box.read(BoxName.tipAmount.toString())));
var res = await CRUD().post(link: AppLink.addTips, payload: {
'passengerID': box.read(BoxName.passengerID),
'driverID': driverList[0].toString(),
'rideID': driverList[1].toString(),
'tipAmount': '1',
'tipAmount': tip.toString(),
});
await CRUD().post(link: AppLink.addPassengersWallet, payload: {
'passenger_id': box.read(BoxName.passengerID).toString(),
'balance': ((-1) * tip).toString()
});
if (res != 'failure') {
FirebaseMessagesController().sendNotificationToAnyWithoutData(
'You Have Tips',
'1\$ tips',
'${tip.toString()}\$ tips\nTotal is ${tip + (Get.find<MapPassengerController>().totalPassenger)}',
driverList[2].toString(),
);
}
@@ -223,7 +247,8 @@ class FirebaseMessagesController extends GetxController {
cancel: MyElevatedButton(
title: 'No,I want'.tr,
onPressed: () {
Get.offAll(() => RateCaptainFromPassenger());
Get.back();
Get.off(() => RateCaptainFromPassenger());
},
kolor: AppColor.redColor,
));
@@ -411,3 +436,98 @@ class FirebaseMessagesController extends GetxController {
}
}
}
class DriverTipWidget extends StatelessWidget {
const DriverTipWidget({
super.key,
});
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Your fee is ${Get.find<MapPassengerController>().totalPassenger.toStringAsFixed(2)}'),
Text('Do you want to pay Tips for this Driver'.tr),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
InkWell(
onTap: () {
box.write(BoxName.tipAmount, '0.05');
Toast.show(
context,
'Tip is ${(Get.find<MapPassengerController>().totalPassenger) * (double.parse(box.read(BoxName.tipAmount.toString())))}',
AppColor.blueColor);
},
child: Container(
decoration: BoxDecoration(border: Border.all()),
child: const Padding(
padding: EdgeInsets.all(4),
child: Center(
child: Text('5%'),
),
),
),
),
InkWell(
onTap: () {
box.write(BoxName.tipAmount, '0.10');
Toast.show(
context,
'Tip is ${(Get.find<MapPassengerController>().totalPassenger) * (double.parse(box.read(BoxName.tipAmount.toString())))}',
AppColor.blueColor);
},
child: Container(
decoration: BoxDecoration(border: Border.all()),
child: const Center(
child: Padding(
padding: EdgeInsets.all(5),
child: Text('10%'),
),
),
),
),
InkWell(
onTap: () {
box.write(BoxName.tipAmount, '0.15');
Toast.show(
context,
'Tip is ${(Get.find<MapPassengerController>().totalPassenger) * (double.parse(box.read(BoxName.tipAmount.toString())))}',
AppColor.blueColor);
},
child: Container(
decoration: BoxDecoration(border: Border.all()),
child: const Center(
child: Padding(
padding: EdgeInsets.all(5),
child: Text('15%'),
),
),
),
),
InkWell(
onTap: () {
box.write(BoxName.tipAmount, '0.20');
Toast.show(
context,
'Tip is ${(Get.find<MapPassengerController>().totalPassenger) * (double.parse(box.read(BoxName.tipAmount.toString())))}',
AppColor.blueColor);
},
child: Container(
decoration: BoxDecoration(border: Border.all()),
child: const Center(
child: Padding(
padding: EdgeInsets.all(5),
child: Text('20%'),
),
),
),
),
],
)
],
);
}
}

View File

@@ -154,7 +154,7 @@ class CRUD {
},
);
print(response.request);
//print(payload);
print(payload);
var jsonData = jsonDecode(response.body);
if (response.statusCode == 200) {

View File

@@ -57,18 +57,23 @@ class MapDriverController extends GetxController {
late String direction;
late String durationOfRideValue;
late String status;
int timeWaitingPassenger = 5; //5 miniute
bool isPassengerInfoWindow = false;
bool isBtnRideBegin = false;
bool isArrivedSend = true;
bool isBtnPassengerWait = false;
bool isRideFinished = false;
bool isRideStarted = false;
double passengerInfoWindow = Get.height * .35;
double driverEndPage = 100;
double progress = 0;
double progressToPassenger = 0;
double progressInPassengerLocationFromDriver = 0;
bool isRideBegin = false;
int progressTimerToShowPassengerInfoWindowFromDriver = 25;
int remainingTimeToShowPassengerInfoWindowFromDriver = 25;
int remainingTimeToPassenger = 60;
int remainingTimeInPassengerLocatioWait = 60;
bool isDriverNearPassengerStart = false;
GoogleMapController? mapController;
late LatLng myLocation;
@@ -196,6 +201,31 @@ class MapDriverController extends GetxController {
}
}
String stringRemainingTimeWaitingPassenger = '';
void startTimerToShowDriverWaitPassengerDuration() async {
for (int i = 0; i <= timeWaitingPassenger * 60; i++) {
await Future.delayed(const Duration(seconds: 1));
progressInPassengerLocationFromDriver = i / (timeWaitingPassenger * 60);
remainingTimeInPassengerLocatioWait = (timeWaitingPassenger * 60) - i;
if (remainingTimeInPassengerLocatioWait == 0) {
isBtnPassengerWait = true;
print(isBtnPassengerWait);
update();
}
print(isBtnPassengerWait);
print(
'remainingTimeInPassengerLocatioWait $remainingTimeInPassengerLocatioWait');
int minutes = (remainingTimeInPassengerLocatioWait / 60).floor();
int seconds = remainingTimeInPassengerLocatioWait % 60;
stringRemainingTimeWaitingPassenger =
'$minutes:${seconds.toString().padLeft(2, '0')}';
update();
}
}
void driverGoToPassenger() async {
changeRideToBeginToPassenger();
await CRUD().post(link: AppLink.updateRides, payload: {

View File

@@ -17,9 +17,11 @@ class OrderRequestController extends GetxController {
String countRefuse = '0';
bool applied = false;
final locationController = Get.put(LocationController());
@override
void onInit() {
getRefusedOrderByCaptain();
update();
super.onInit();
}

View File

@@ -220,9 +220,11 @@ class MapPassengerController extends GetxController {
clearPolyline();
isMarkersShown = false;
isWayPointStopsSheetUtilGetMap = false;
isWayPointSheet = false;
durationToRide = 0;
distanceOfDestnation = 0;
wayPointSheetHeight = 0;
remainingTime = 25;
haveSteps = true;
// Filter out empty value
@@ -447,7 +449,7 @@ class MapPassengerController extends GetxController {
String stringRemainingTimeToPassenger = '';
void startTimerToPassengerFromDriverAfterApplied() async {
void startTimerFromDriverToPassengerAfterApplied() async {
for (int i = 0; i <= timeToPassengerFromDriverAfterApplied; i++) {
await Future.delayed(const Duration(seconds: 1));
progressTimerToPassengerFromDriverAfterApplied =
@@ -466,6 +468,16 @@ class MapPassengerController extends GetxController {
int seconds = remainingTimeToPassengerFromDriverAfterApplied % 60;
stringRemainingTimeToPassenger =
'$minutes:${seconds.toString().padLeft(2, '0')}';
// var cameraUpdate = CameraUpdate.newLatLngZoom(
// driverLocationToPassenger,
// 17,
// );
// mapController!.animateCamera(cameraUpdate);
// print(driverCarsLocationToPassengerAfterApplied);
// print(driverCarsLocationToPassengerAfterApplied[0]);
update();
}
}
@@ -531,10 +543,38 @@ class MapPassengerController extends GetxController {
timeToPassengerFromDriverAfterApplied = 0;
remainingTime = 0;
remainingTimeToPassengerFromDriverAfterApplied = 0;
rideTimerBegin = true;
update();
// isCancelRidePageShown = true;
rideIsBeginPassengerTimer();
// //print('rideTimerBegin: $rideTimerBegin');
rideTimerBegin = true;
}
} catch (e) {
//print('Error: $e');
// Handle the error or perform any necessary actions
}
}
void getRideStatusFromStartApp() async {
try {
var res = await CRUD().get(
link: AppLink.getRideStatusFromStartApp,
payload: {'passenger_id': box.read(BoxName.passengerID)});
if (res == 'failure') {
//print(res);
}
var decode = jsonDecode(res);
if (decode['data']['status'] == 'Begin') {
getMap(
decode['data']['start_location'], decode['data']['end_location']);
// timeToPassengerFromDriverAfterApplied = 0;
// remainingTime = 0;
// remainingTimeToPassengerFromDriverAfterApplied = 0;
// // isCancelRidePageShown = true;
// rideIsBeginPassengerTimer();
// // //print('rideTimerBegin: $rideTimerBegin');
// rideTimerBegin = true;
update();
}
} catch (e) {
@@ -610,6 +650,8 @@ class MapPassengerController extends GetxController {
late String model;
late String licensePlate;
changeConfirmRide() async {
await getCarsLocationByPassenger();
if (dataCarsLocationByPassenger != 'failure') {
driverToken =
dataCarsLocationByPassenger['message'][carsOrder]['token'].toString();
@@ -633,7 +675,6 @@ class MapPassengerController extends GetxController {
update();
// //print('rideConfirm= $rideConfirm');
await getCarsLocationByPassenger();
await CRUD().post(link: AppLink.addRides, payload: {
"start_location": //'${data[0]['start_address']}',
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
@@ -772,7 +813,7 @@ class MapPassengerController extends GetxController {
// //print('timeToPassengerFromDriverAfterApplied====' +
// timeToPassengerFromDriverAfterApplied.toString());
startTimerToPassengerFromDriverAfterApplied();
startTimerFromDriverToPassengerAfterApplied();
update();
}
update();
@@ -839,23 +880,25 @@ class MapPassengerController extends GetxController {
}
}
late LatLng driverLocationToPassenger = LatLng(32, 35);
Future getDriverCarsLocationToPassengerAfterApplied() async {
driverCarsLocationToPassengerAfterApplied = [];
var res = await CRUD().get(
link: AppLink.getDriverCarsLocationToPassengerAfterApplied,
payload: {
'driver_id': dataCarsLocationByPassenger['message'][carsOrder]
['driver_id']
});
payload: {'driver_id': driverId});
datadriverCarsLocationToPassengerAfterApplied = jsonDecode(res);
driverLocationToPassenger = LatLng(
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['latitude']),
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['longitude']));
driverCarsLocationToPassengerAfterApplied.add(LatLng(
double.parse(datadriverCarsLocationToPassengerAfterApplied['message']
[carsOrder]['latitude']),
double.parse(datadriverCarsLocationToPassengerAfterApplied['message']
[carsOrder]['longitude'])));
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['latitude']),
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['longitude'])));
update();
}
@@ -939,7 +982,7 @@ class MapPassengerController extends GetxController {
// clearPolylineAll();
data = [];
changeCancelRidePageShow();
if (rideId != '') {
if (rideId != 'yet') {
await CRUD().post(link: AppLink.updateDriverOrder, payload: {
"order_id": rideId.toString(), // Convert to String
"status": 'Cancel'
@@ -957,6 +1000,7 @@ class MapPassengerController extends GetxController {
// totalStepDurations = 0;
timeToPassengerFromDriverAfterApplied = 0;
remainingTime = 0;
isWayPointStopsSheetUtilGetMap = false;
update();
} else {
clearPlacesDestination();
@@ -969,6 +1013,7 @@ class MapPassengerController extends GetxController {
FirebaseMessagesController().sendNotificationToDriverMAP(
'Cancel Trip', 'Trip Cancelled'.tr, driverToken, []);
isPickerShown = false;
isWayPointStopsSheetUtilGetMap = false;
rideConfirm = false;
shouldFetch = false;
isCashConfirmPageShown = false;
@@ -1008,7 +1053,7 @@ class MapPassengerController extends GetxController {
} else {
isMainBottomMenuMap = !isMainBottomMenuMap;
mainBottomMenuMapHeight =
isMainBottomMenuMap == true ? Get.height * .2 : Get.height * .5;
isMainBottomMenuMap == true ? Get.height * .2 : Get.height * .6;
isWayPointSheet = false;
if (heightMenuBool == true) {
getDrawerMenu();
@@ -1021,10 +1066,13 @@ class MapPassengerController extends GetxController {
void downPoints() {
if (Get.find<WayPointController>().wayPoints.length < 2) {
isWayPointStopsSheetUtilGetMap = false;
changeWayPointStopsSheet();
isWayPointSheet = false;
wayPointSheetHeight = isWayPointStopsSheet ? Get.height * .45 : 0;
// changeWayPointStopsSheet();
update();
}
changeWayPointStopsSheet();
// changeWayPointStopsSheet();
// isWayPointSheet = false;
update();
}
@@ -1475,6 +1523,7 @@ class MapPassengerController extends GetxController {
late LatLngBounds boundsData;
getMap(String origin, destination) async {
remainingTime = 25; //to make cancel every call
await getCarsLocationByPassenger();
// //print(carsLocationByPassenger);
var coordDestination = destination.split(',');
@@ -1694,7 +1743,7 @@ class MapPassengerController extends GetxController {
print('boundsbounds');
// Fit the camera to the bounds
var cameraUpdate = CameraUpdate.newLatLngBounds(bounds, 160);
var cameraUpdate = CameraUpdate.newLatLngBounds(bounds, 180);
mapController!.animateCamera(cameraUpdate);
update();
}

View File

@@ -40,8 +40,9 @@ class CaptainWalletController extends GetxController {
walletDriverPointsDate = jsonDecode(res);
if (walletDriverPointsDate['message'][0]['driverID'].toString() ==
box.read(BoxName.driverID)) {
totalPoints =
walletDriverPointsDate['message'][0]['total_amount'].toString();
double totalPointsDouble = double.parse(
walletDriverPointsDate['message'][0]['total_amount'].toString());
totalPoints = totalPointsDouble.toStringAsFixed(0);
} else {
totalPoints = '0';
}