9/13/1
This commit is contained in:
@@ -59,8 +59,12 @@ class MapController extends GetxController {
|
||||
var dataCarsLocationByPassenger;
|
||||
CarLocation? nearestCar;
|
||||
late Timer markerReloadingTimer;
|
||||
|
||||
bool shouldFetch = true; // Flag to determine if fetch should be executed
|
||||
int selectedPassengerCount = 1;
|
||||
double progress = 0;
|
||||
int durationTimer = 25;
|
||||
int remainingTime = 0;
|
||||
|
||||
void onChangedPassengerCount(int newValue) {
|
||||
selectedPassengerCount = newValue;
|
||||
update();
|
||||
@@ -126,9 +130,11 @@ class MapController extends GetxController {
|
||||
}
|
||||
|
||||
changeConfirmRide() async {
|
||||
// rideConfirm = true;
|
||||
// update();
|
||||
rideConfirm = true;
|
||||
shouldFetch = true;
|
||||
update();
|
||||
// print('rideConfirm= $rideConfirm');
|
||||
var rideId;
|
||||
await getCarsLocationByPassenger();
|
||||
await CRUD().post(link: AppLink.addRides, payload: {
|
||||
"start_location": '${data[0]['start_address']}',
|
||||
@@ -148,6 +154,7 @@ class MapController extends GetxController {
|
||||
}).then((value) {
|
||||
// print(jsonDecode(value)['message']);
|
||||
// List<String> body = [
|
||||
rideId = jsonDecode(value)['message'];
|
||||
List<String> body = [
|
||||
// '${data[0]['start_address']}',
|
||||
// '${data[0]['end_address']}',
|
||||
@@ -171,29 +178,63 @@ class MapController extends GetxController {
|
||||
dataCarsLocationByPassenger['message'][0]['token'].toString(),
|
||||
body,
|
||||
);
|
||||
// FirebasMessagesController().sendNotificationToDriverId(
|
||||
// 'Order',
|
||||
// jsonDecode(value)['message'].toString(),
|
||||
// body[0],
|
||||
// body[1],
|
||||
// body[2],
|
||||
// body[3],
|
||||
// body[4],
|
||||
// body[5],
|
||||
// body[6],
|
||||
// body[7],
|
||||
// body[8],
|
||||
// body[9],
|
||||
// body[10],
|
||||
// dataCarsLocationByPassenger['message'][0]['token'].toString(),
|
||||
// );
|
||||
print(dataCarsLocationByPassenger);
|
||||
print(dataCarsLocationByPassenger['message'][0]['token'].toString());
|
||||
// print(dataCarsLocationByPassenger);
|
||||
// print(dataCarsLocationByPassenger['message'][0]['token'].toString());
|
||||
});
|
||||
|
||||
delayAndFetchRideStatus(rideId);
|
||||
if (shouldFetch == false) {
|
||||
startTimer();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void delayAndFetchRideStatus(String rideId) {
|
||||
Timer(const Duration(seconds: 3), () async {
|
||||
if (shouldFetch) {
|
||||
// print('shouldFetch is =$shouldFetch');
|
||||
var res = await CRUD()
|
||||
.get(link: AppLink.getRideStatus, payload: {'order_id': rideId});
|
||||
var decod = jsonDecode(res);
|
||||
// print(' 0000000000000000000000000000000000000000000000000');
|
||||
// print(decod['data']);
|
||||
if (decod['data'].toString() == 'Apply' ||
|
||||
decod['data'].toString() == 'Refused') {
|
||||
shouldFetch = false; // Stop further fetches
|
||||
rideConfirm = false;
|
||||
|
||||
update();
|
||||
} else {
|
||||
delayAndFetchRideStatus(
|
||||
rideId); // Repeat the delay and fetch operation
|
||||
}
|
||||
}
|
||||
});
|
||||
startTimer();
|
||||
}
|
||||
|
||||
void startTimer() async {
|
||||
for (int i = 0; i <= durationTimer; i++) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
progress = i / durationTimer;
|
||||
remainingTime = durationTimer - i;
|
||||
|
||||
update();
|
||||
}
|
||||
timerEnded();
|
||||
}
|
||||
|
||||
void timerEnded() async {
|
||||
print('Timer ended');
|
||||
// refuseOrder();
|
||||
}
|
||||
|
||||
Future<String> getRideStatus(int rideId) async {
|
||||
final response = await CRUD()
|
||||
.get(link: AppLink.getRideStatus, payload: {'order_id': rideId});
|
||||
|
||||
return response['status'];
|
||||
}
|
||||
|
||||
Future cancelRide() async {
|
||||
print(rideConfirm);
|
||||
|
||||
@@ -202,11 +243,13 @@ class MapController extends GetxController {
|
||||
clearpolyline();
|
||||
data = [];
|
||||
changeCancelRidePageShow();
|
||||
rideConfirm = false;
|
||||
update();
|
||||
} else {
|
||||
clearPlaces();
|
||||
clearpolyline();
|
||||
data = [];
|
||||
rideConfirm = false;
|
||||
changeCancelRidePageShow();
|
||||
|
||||
await CRUD().post(link: AppLink.addCancelRide, payload: {
|
||||
@@ -349,7 +392,7 @@ class MapController extends GetxController {
|
||||
Future getCarsLocationByPassenger() async {
|
||||
carsLocationByPassenger = [];
|
||||
LatLngBounds bounds =
|
||||
calculateBounds(mylocation.latitude, mylocation.longitude, 10);
|
||||
calculateBounds(mylocation.latitude, mylocation.longitude, 8000);
|
||||
print(
|
||||
'Southwest: ${bounds.southwest.latitude}, ${bounds.southwest.longitude}');
|
||||
print(
|
||||
|
||||
Reference in New Issue
Block a user