This commit is contained in:
Hamza-Ayed
2023-09-11 19:12:33 +03:00
parent a626915f45
commit 8b0b5e9cef
10 changed files with 556 additions and 275 deletions

View File

@@ -0,0 +1,42 @@
import 'package:get/get.dart';
import 'package:ride/constant/links.dart';
import '../../functions/crud.dart';
class TimerController extends GetxController {
double progress = 0;
int duration = 25;
int remainingTime = 0;
@override
void onInit() {
startTimer();
super.onInit();
}
void startTimer() async {
for (int i = 0; i <= duration; i++) {
await Future.delayed(const Duration(seconds: 1));
progress = i / duration;
remainingTime = duration - i;
update();
}
timerEnded();
}
void refuseOrder(String driverID, orderID) async {
await CRUD().postFromDialogue(link: AppLink.addDriverOrder, payload: {
'driver_id': driverID,
// box.read(BoxName.driverID).toString(),
'order_id': orderID,
'status': 'Refused'
});
Get.back();
}
void timerEnded() async {
print('Timer ended');
// refuseOrder();
}
}

View File

@@ -126,12 +126,12 @@ class MapController extends GetxController {
}
changeConfirmRide() async {
rideConfirm = true;
print('rideConfirm= $rideConfirm');
// rideConfirm = true;
// 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']}',
"end_location": '${data[0]['end_address']}',
// '${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
@@ -147,6 +147,7 @@ class MapController extends GetxController {
"distance": distance.toString()
}).then((value) {
// print(jsonDecode(value)['message']);
// List<String> body = [
List<String> body = [
// '${data[0]['start_address']}',
// '${data[0]['end_address']}',
@@ -157,21 +158,37 @@ class MapController extends GetxController {
duration.toString(),
distance.toString(),
dataCarsLocationByPassenger['message'][0]['id'].toString(),
box.read(BoxName.pasengerID).toString()
box.read(BoxName.pasengerID).toString(),
box.read(BoxName.name).toString(),
box.read(BoxName.tokenFCM).toString(),
box.read(BoxName.phone).toString(),
duratioByPassenger.toString(),
distanceByPassenger.toString(),
];
FirebasMessagesController().sendNotificationDriverId(
FirebasMessagesController().sendNotificationToDriverMAP(
'Order',
jsonDecode(value)['message'].toString(),
body[0],
body[1],
body[2],
body[3],
body[4],
body[5],
body[6],
body[7],
box.read(BoxName.tokenFCM).toString(), //TODO change to Driver
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());
});
update();
@@ -372,7 +389,7 @@ class MapController extends GetxController {
LatLngBounds calculateBounds(
double centerLat, double centerLng, double radius) {
double radius = 2000; // 10 km in meters
double radius = 4000; // 10 km in meters
southwest = LatLng(
centerLat - (radius / 111000),
@@ -449,6 +466,7 @@ class MapController extends GetxController {
}
String duratioByPassenger = '';
String distanceByPassenger = '';
void getNearestDriverByPassengerLocation() async {
if (polylines.isEmpty || data.isEmpty) {
double nearestDistance = double.infinity;
@@ -471,7 +489,7 @@ class MapController extends GetxController {
// longitude: double.parse(carLocation['longitude']),
// );
// }
isloading = true;
// isloading = true;
update();
// Make API request to get exact distance and duration
String apiUrl =
@@ -481,6 +499,8 @@ class MapController extends GetxController {
var data = response;
// Extract distance and duration from the response and handle accordingly
int distance1 = data['rows'][0]['elements'][0]['distance']['value'];
distanceByPassenger =
data['rows'][0]['elements'][0]['distance']['text'];
duration1 = data['rows'][0]['elements'][0]['duration']['value'];
duratioByPassenger =
data['rows'][0]['elements'][0]['duration']['text'];
@@ -495,7 +515,7 @@ class MapController extends GetxController {
latitude: double.parse(carLocation['latitude']),
longitude: double.parse(carLocation['longitude']),
);
isloading = false;
// isloading = false;
update();
}
}