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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -199,7 +199,7 @@ class DriverArrivePassengerAndWaitMinute extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'The driver waitting you in picked location .'.tr,
'The driver waiting you in picked location .'.tr,
style: AppStyle.title,
textAlign: TextAlign.center,
),
@@ -251,9 +251,19 @@ class TimeDriverToPassenger extends StatelessWidget {
: AppColor.greenColor,
minHeight: 25,
borderRadius: BorderRadius.circular(15),
value: controller
.progressTimerToPassengerFromDriverAfterApplied
.toDouble(),
value: () {
// Ensure valid value between 0.0 and 1.0
double progress = controller
.progressTimerToPassengerFromDriverAfterApplied
.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(
child: Row(