This commit is contained in:
Hamza Aleghwairyeen
2024-04-02 13:51:34 +03:00
parent aa20cd4455
commit 44fe1f494d
8 changed files with 74 additions and 54 deletions

View File

@@ -326,9 +326,9 @@ update ui for totla results
*/ */
} }
void startRideFromDriver() async { startRideFromDriver() async {
double _distance = double _distance =
await calculateDistanseBetweenDriverAndPassengerLocation(); await calculateDistanceBetweenDriverAndPassengerLocation();
if (_distance < 50) { if (_distance < 50) {
changeRideToBeginToPassenger(); changeRideToBeginToPassenger();
@@ -340,6 +340,11 @@ update ui for totla results
box.write(BoxName.statusDriverLocation, 'on'); box.write(BoxName.statusDriverLocation, 'on');
update(); update();
await CRUD().post(link: AppLink.updateRides, payload: {
'id': rideId,
'rideTimeStart': DateTime.now().toString(),
'status': 'Begin',
});
await CRUD().post(link: AppLink.addDriverpayment, payload: { await CRUD().post(link: AppLink.addDriverpayment, payload: {
'rideId': rideId, 'rideId': rideId,
'amount': paymentAmount, 'amount': paymentAmount,
@@ -348,16 +353,14 @@ update ui for totla results
'driverID': box.read(BoxName.driverID).toString(), 'driverID': box.read(BoxName.driverID).toString(),
}); });
await CRUD().post(link: AppLink.updateRides, payload: {
'id': rideId,
'rideTimeStart': DateTime.now().toString(),
'status': 'Begin',
});
FirebaseMessagesController().sendNotificationToAnyWithoutData( FirebaseMessagesController().sendNotificationToAnyWithoutData(
'RideIsBegin', box.read(BoxName.name).toString(), tokenPassenger); 'RideIsBegin', box.read(BoxName.name).toString(), tokenPassenger);
rideIsBeginPassengerTimer(); rideIsBeginPassengerTimer();
double pointsSubstraction = 0; double pointsSubstraction = 0;
pointsSubstraction = double.parse(paymentAmount) * -17; pointsSubstraction = double.parse(paymentAmount) *
(-1) *
double.parse(kazan) /
100; // for eygpt /100
var res = var res =
await CRUD().post(link: AppLink.addDriversWalletPoints, payload: { await CRUD().post(link: AppLink.addDriversWalletPoints, payload: {
'paymentID': 'rideId$rideId', 'paymentID': 'rideId$rideId',
@@ -385,7 +388,7 @@ update ui for totla results
} }
} }
calcualateDistsanceInMetet(LatLng prev, LatLng current) async { calculateDistanceInMeter(LatLng prev, LatLng current) async {
double distance2 = Geolocator.distanceBetween( double distance2 = Geolocator.distanceBetween(
prev.latitude, prev.latitude,
prev.longitude, prev.longitude,
@@ -408,7 +411,7 @@ update ui for totla results
latestPosition = position as LatLng?; // Update latest position latestPosition = position as LatLng?; // Update latest position
// Calculate distance using the latest position // Calculate distance using the latest position
double distance = calcualateDistsanceInMetet( double distance = calculateDistanceInMeter(
currentPosition as LatLng, latestPosition!); currentPosition as LatLng, latestPosition!);
speedoMeter = distance + speedoMeter; speedoMeter = distance + speedoMeter;
print('distance is $distance'); print('distance is $distance');
@@ -441,7 +444,7 @@ update ui for totla results
updateLocation(); updateLocation();
} }
calculateDistanseBetweenDriverAndPassengerLocation() { calculateDistanceBetweenDriverAndPassengerLocation() {
double distance2 = Geolocator.distanceBetween( double distance2 = Geolocator.distanceBetween(
latLngpassengerLocation.latitude, latLngpassengerLocation.latitude,
latLngpassengerLocation.longitude, latLngpassengerLocation.longitude,
@@ -451,8 +454,8 @@ update ui for totla results
return distance2; return distance2;
} }
addWaittingTimeCostFromPassengerToDriverWallet() async { addWaitingTimeCostFromPassengerToDriverWallet() async {
double distance2 = calculateDistanseBetweenDriverAndPassengerLocation(); double distance2 = calculateDistanceBetweenDriverAndPassengerLocation();
if (distance2 > 40) { if (distance2 > 40) {
Get.defaultDialog( Get.defaultDialog(
@@ -465,11 +468,12 @@ update ui for totla results
Get.back(); Get.back();
})); }));
} else { } else {
double cost = double costOfWaiting5Minute =
(distanceBetweenDriverAndPassengerWhenConfirm * .08) + (5 * .06); (distanceBetweenDriverAndPassengerWhenConfirm * .08) +
(5 * 1); //for Eygpt other like jordan .06 per minute
var res = await CRUD().post(link: AppLink.addDriverpayment, payload: { var res = await CRUD().post(link: AppLink.addDriverpayment, payload: {
'rideId': rideId, 'rideId': rideId,
'amount': cost.toString(), 'amount': costOfWaiting5Minute.toString(),
'payment_method': 'wait-cancel', 'payment_method': 'wait-cancel',
'passengerID': passengerId, 'passengerID': passengerId,
'driverID': box.read(BoxName.driverID).toString(), 'driverID': box.read(BoxName.driverID).toString(),
@@ -477,13 +481,13 @@ update ui for totla results
if (res != 'failure') { if (res != 'failure') {
Get.snackbar( Get.snackbar(
'You will get cost of your work for this trip'.tr, 'You will get cost of your work for this trip'.tr,
'${'you gain'.tr} $cost \$${' in your wallet'.tr}', '${'you gain'.tr} $costOfWaiting5Minute \$${' in your wallet'.tr}',
backgroundColor: AppColor.deepPurpleAccent, backgroundColor: AppColor.deepPurpleAccent,
); );
} }
await CRUD().post(link: AppLink.addPassengersWallet, payload: { await CRUD().post(link: AppLink.addPassengersWallet, payload: {
'passenger_id': passengerId, 'passenger_id': passengerId,
'balance': (cost * -1).toString() 'balance': (costOfWaiting5Minute * -1).toString()
}); });
box.write(BoxName.statusDriverLocation, 'off'); box.write(BoxName.statusDriverLocation, 'off');
Get.offAll(HomeCaptain()); Get.offAll(HomeCaptain());
@@ -501,7 +505,7 @@ update ui for totla results
isRideFinished = true; isRideFinished = true;
isRideStarted = false; isRideStarted = false;
isPriceWindow = false; isPriceWindow = false;
if (cartype == 'Comfort' || cartype == 'Free Ride') { if (carType == 'Comfort' || carType == 'Free Ride') {
totalCost = price.toStringAsFixed(2); totalCost = price.toStringAsFixed(2);
paymentAmount = totalCost; paymentAmount = totalCost;
// update(); // update();
@@ -602,15 +606,15 @@ update ui for totla results
await Future.delayed(const Duration(seconds: 1)); await Future.delayed(const Duration(seconds: 1));
recentDistanceToDash = Get.find<LocationController>().totalDistance; recentDistanceToDash = Get.find<LocationController>().totalDistance;
rideTimerFromBegin = i; rideTimerFromBegin = i;
price = cartype == 'Comfort' || cartype == 'Free Ride' price = carType == 'Comfort' || carType == 'Free Ride'
? (i ~/ 60) + ? (i ~/ 60) +
(recentDistanceToDash * (recentDistanceToDash *
Get.find<HomeCaptainController>().comfortPrice) Get.find<HomeCaptainController>().comfortPrice)
: cartype == 'Speed' : carType == 'Speed'
? (i ~/ 60) + ? (i ~/ 60) +
(recentDistanceToDash * (recentDistanceToDash *
Get.find<HomeCaptainController>().speedPrice) Get.find<HomeCaptainController>().speedPrice)
: cartype == 'Delivery' : carType == 'Delivery'
? (i ~/ 60) + ? (i ~/ 60) +
(recentDistanceToDash * (recentDistanceToDash *
Get.find<HomeCaptainController>().deliveryPrice) Get.find<HomeCaptainController>().deliveryPrice)
@@ -877,7 +881,8 @@ LIMIT
late Duration durationToAdd; late Duration durationToAdd;
int hours = 0; int hours = 0;
int minutes = 0; int minutes = 0;
late String cartype; late String carType;
late String kazan;
@override @override
void onInit() async { void onInit() async {
mapAPIKEY = await storage.read(key: BoxName.mapAPIKEY); mapAPIKEY = await storage.read(key: BoxName.mapAPIKEY);
@@ -909,7 +914,8 @@ LIMIT
step4 = Get.arguments['step4']; step4 = Get.arguments['step4'];
passengerWalletBurc = Get.arguments['passengerWalletBurc']; passengerWalletBurc = Get.arguments['passengerWalletBurc'];
timeOfOrder = Get.arguments['timeOfOrder']; timeOfOrder = Get.arguments['timeOfOrder'];
cartype = Get.arguments['carType']; carType = Get.arguments['carType'];
kazan = Get.arguments['kazan'];
var coords = passengerLocation.split(','); var coords = passengerLocation.split(',');
var coordDestination = passengerDestination.split(','); var coordDestination = passengerDestination.split(',');

View File

@@ -47,9 +47,9 @@ class MapPassengerController extends GetxController {
List<LatLng> bounds = []; List<LatLng> bounds = [];
List placesStart = []; List placesStart = [];
List<String> driversToken = []; List<String> driversToken = [];
LatLng previousLocationOfDrivers = LatLng(0, 0); LatLng previousLocationOfDrivers = const LatLng(0, 0);
double angleDegrees = 0; double angleDegrees = 0;
LatLng currentLocationOfDrivers = LatLng(0, 0); LatLng currentLocationOfDrivers = const LatLng(0, 0);
List<TextEditingController> allTextEditingPlaces = []; List<TextEditingController> allTextEditingPlaces = [];
List placesDestination = []; List placesDestination = [];
List wayPoint0 = []; List wayPoint0 = [];
@@ -598,7 +598,6 @@ class MapPassengerController extends GetxController {
rideTimerBegin = false; rideTimerBegin = false;
isRideFinished = true; isRideFinished = true;
update(); update();
} }
void tripFinishedFromDriver() async { void tripFinishedFromDriver() async {
@@ -670,7 +669,8 @@ class MapPassengerController extends GetxController {
remainingTime = 0; remainingTime = 0;
// isCancelRidePageShown = true; // isCancelRidePageShown = true;
update(); update();
rideIsBeginPassengerTimer();runWhenRideIsBegin(); rideIsBeginPassengerTimer();
runWhenRideIsBegin();
} }
void cancelTimerToPassengerFromDriverAfterApplied() { void cancelTimerToPassengerFromDriverAfterApplied() {
@@ -832,6 +832,7 @@ class MapPassengerController extends GetxController {
startNameAddress, startNameAddress,
endNameAddress, endNameAddress,
box.read(BoxName.carType), box.read(BoxName.carType),
kazan.toStringAsFixed(0),
]; ];
print(body); print(body);
FirebaseMessagesController().sendNotificationToDriverMapPolyline( FirebaseMessagesController().sendNotificationToDriverMapPolyline(
@@ -908,6 +909,7 @@ class MapPassengerController extends GetxController {
startNameAddress, startNameAddress,
endNameAddress, endNameAddress,
box.read(BoxName.carType), box.read(BoxName.carType),
kazan.toStringAsFixed(0),
]; ];
print('driversToken'); print('driversToken');
print(driversToken); print(driversToken);
@@ -1133,7 +1135,7 @@ class MapPassengerController extends GetxController {
} }
} }
LatLng driverLocationToPassenger = LatLng(32, 35); LatLng driverLocationToPassenger = const LatLng(32, 35);
Future getDriverCarsLocationToPassengerAfterApplied() async { Future getDriverCarsLocationToPassengerAfterApplied() async {
driverCarsLocationToPassengerAfterApplied = []; driverCarsLocationToPassengerAfterApplied = [];
@@ -1187,8 +1189,8 @@ class MapPassengerController extends GetxController {
void clearMarkersExceptStartEnd() { void clearMarkersExceptStartEnd() {
Set<Marker> markersToRemove = markers Set<Marker> markersToRemove = markers
.where((marker) => .where((marker) =>
marker.markerId != MarkerId("start") && marker.markerId != const MarkerId("start") &&
marker.markerId != MarkerId("end")) marker.markerId != const MarkerId("end"))
.toSet(); .toSet();
for (Marker marker in markersToRemove) { for (Marker marker in markersToRemove) {
@@ -1201,10 +1203,10 @@ class MapPassengerController extends GetxController {
clearMarkersExceptStartEnd(); clearMarkersExceptStartEnd();
// for (var i = 0; i < driverCarsLocationToPassengerAfterApplied.length; i++) { // for (var i = 0; i < driverCarsLocationToPassengerAfterApplied.length; i++) {
LatLng driverPosition = LatLng( LatLng driverPosition = LatLng(
double.parse( double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
datadriverCarsLocationToPassengerAfterApplied[0]['latitude']), ['latitude']),
double.parse( double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
datadriverCarsLocationToPassengerAfterApplied[0]['longitude'])); ['longitude']));
final driverAcceptedMarker = Marker( final driverAcceptedMarker = Marker(
markerId: const MarkerId('driverToPassengers'), markerId: const MarkerId('driverToPassengers'),
position: driverPosition, position: driverPosition,
@@ -1921,14 +1923,14 @@ class MapPassengerController extends GetxController {
data[0]["start_location"]['lat'], data[0]["start_location"]['lng']); data[0]["start_location"]['lat'], data[0]["start_location"]['lng']);
markers.add( markers.add(
Marker( Marker(
markerId: MarkerId('start'), markerId: const MarkerId('start'),
position: newStartPointLocation, position: newStartPointLocation,
icon: startIcon, icon: startIcon,
), ),
); );
markers.add( markers.add(
Marker( Marker(
markerId: MarkerId('end'), markerId: const MarkerId('end'),
position: LatLng( position: LatLng(
data[0]["end_location"]['lat'], data[0]["end_location"]['lng']), data[0]["end_location"]['lat'], data[0]["end_location"]['lng']),
icon: endIcon, icon: endIcon,

View File

@@ -48,10 +48,10 @@ class RatePassenger extends StatelessWidget {
child: Padding( child: Padding(
padding: const EdgeInsets.all(4), padding: const EdgeInsets.all(4),
child: Text( child: Text(
Get.find<MapDriverController>().cartype == Get.find<MapDriverController>().carType ==
'Comfort' || 'Comfort' ||
Get.find<MapDriverController>() Get.find<MapDriverController>()
.cartype == .carType ==
'Free Ride' 'Free Ride'
? Get.find<MapDriverController>() ? Get.find<MapDriverController>()
.price .price

View File

@@ -65,7 +65,7 @@ GetBuilder<MapDriverController> driverEndRideBar() {
'Price is ${mapDriverController.price.toStringAsFixed(0)}') 'Price is ${mapDriverController.price.toStringAsFixed(0)}')
], ],
), ),
mapDriverController.cartype == 'Free Ride' mapDriverController.carType == 'Free Ride'
? Row( ? Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
@@ -80,7 +80,7 @@ GetBuilder<MapDriverController> driverEndRideBar() {
) )
: const SizedBox(), : const SizedBox(),
mapDriverController.remainingTimeTimerRideBegin < 60 && mapDriverController.remainingTimeTimerRideBegin < 60 &&
mapDriverController.cartype != 'Free Ride' mapDriverController.carType != 'Free Ride'
? Row( ? Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [

View File

@@ -219,8 +219,8 @@ class PassengerInfoWindow extends StatelessWidget {
.tr, .tr,
confirm: MyElevatedButton( confirm: MyElevatedButton(
title: 'OK'.tr, title: 'OK'.tr,
onPressed: () { onPressed: () async {
controller await controller
.startRideFromDriver(); .startRideFromDriver();
Get.back(); Get.back();
}), }),
@@ -238,7 +238,7 @@ class PassengerInfoWindow extends StatelessWidget {
kolor: AppColor.yellowColor, kolor: AppColor.yellowColor,
onPressed: () async { onPressed: () async {
if (controller if (controller
.calculateDistanseBetweenDriverAndPassengerLocation() < .calculateDistanceBetweenDriverAndPassengerLocation() <
40) { 40) {
FirebaseMessagesController() FirebaseMessagesController()
.sendNotificationToPassengerToken( .sendNotificationToPassengerToken(
@@ -334,7 +334,7 @@ class PassengerInfoWindow extends StatelessWidget {
.tokenPassenger, .tokenPassenger,
[]); []);
await controller await controller
.addWaittingTimeCostFromPassengerToDriverWallet(); .addWaitingTimeCostFromPassengerToDriverWallet();
controller controller
.isdriverWaitTimeEnd = .isdriverWaitTimeEnd =
false; false;

View File

@@ -352,6 +352,7 @@ class OrderRequestPage extends StatelessWidget {
'timeOfOrder': DateTime.now().toString(), 'timeOfOrder': DateTime.now().toString(),
'totalPassenger': myList[2].toString(), 'totalPassenger': myList[2].toString(),
'carType': myList[31].toString(), 'carType': myList[31].toString(),
'kazan': myList[32].toString(),
}); });
}, },
), ),

View File

@@ -306,9 +306,9 @@ class OrderSpeedRequest extends StatelessWidget {
'driver_id': box.read(BoxName.driverID), 'driver_id': box.read(BoxName.driverID),
}); });
// .then((value) { // .then((value) {
var json = jsonDecode(res); // var json = jsonDecode(res);
print('res $json'); print('res $res');
if (json['status'] == "failure") { if (res == "failure") {
Get.defaultDialog( Get.defaultDialog(
title: title:
"This ride is already taken by another driver." "This ride is already taken by another driver."
@@ -318,7 +318,7 @@ class OrderSpeedRequest extends StatelessWidget {
middleTextStyle: AppStyle.title, middleTextStyle: AppStyle.title,
confirm: MyElevatedButton( confirm: MyElevatedButton(
title: 'Ok'.tr, onPressed: () => Get.back())); title: 'Ok'.tr, onPressed: () => Get.back()));
} else if (json['status'] == "success") { } else if (jsonDecode(res)['status'] == "success") {
List<String> bodyToPassenger = [ List<String> bodyToPassenger = [
box.read(BoxName.driverID).toString(), box.read(BoxName.driverID).toString(),
box.read(BoxName.nameDriver).toString(), box.read(BoxName.nameDriver).toString(),
@@ -374,6 +374,7 @@ class OrderSpeedRequest extends StatelessWidget {
'timeOfOrder': DateTime.now().toString(), 'timeOfOrder': DateTime.now().toString(),
'totalPassenger': myList[2].toString(), 'totalPassenger': myList[2].toString(),
'carType': myList[31].toString(), 'carType': myList[31].toString(),
'kazan': myList[32].toString(),
}); });
} }
// }); // });

View File

@@ -199,7 +199,7 @@ class DriverArrivePassengerAndWaitMinute extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text( Text(
'The driver waitting you in picked location .'.tr, 'The driver waiting you in picked location .'.tr,
style: AppStyle.title, style: AppStyle.title,
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
@@ -251,9 +251,19 @@ class TimeDriverToPassenger extends StatelessWidget {
: AppColor.greenColor, : AppColor.greenColor,
minHeight: 25, minHeight: 25,
borderRadius: BorderRadius.circular(15), borderRadius: BorderRadius.circular(15),
value: controller value: () {
// Ensure valid value between 0.0 and 1.0
double progress = controller
.progressTimerToPassengerFromDriverAfterApplied .progressTimerToPassengerFromDriverAfterApplied
.toDouble(), .toDouble();
if (progress.isNaN || progress.isInfinite) {
// Handle invalid progress (e.g., set to 0.0)
return 0.0;
} else {
return progress.clamp(
0.0, 1.0); // Clamp to valid range
}
}(),
), ),
Center( Center(
child: Row( child: Row(