2/25/1
This commit is contained in:
@@ -9,6 +9,7 @@ import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:location/location.dart';
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/constant/style.dart';
|
||||
@@ -120,6 +121,9 @@ class MapPassengerController extends GetxController {
|
||||
bool rideConfirm = false;
|
||||
bool isMarkersShown = false;
|
||||
bool isMainBottomMenuMap = true;
|
||||
late Timer markerReloadingTimer2;
|
||||
late Timer markerReloadingTimer1;
|
||||
late int duration1;
|
||||
bool isWayPointSheet = false;
|
||||
bool isWayPointStopsSheet = false;
|
||||
bool isWayPointStopsSheetUtilGetMap = false;
|
||||
@@ -516,7 +520,13 @@ class MapPassengerController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
late String arrivalTime;
|
||||
void rideIsBeginPassengerTimer() async {
|
||||
// Calculate arrival time considering current time and duration
|
||||
DateTime now = DateTime.now();
|
||||
DateTime arrivalTime1 = now.add(Duration(seconds: durationToRide));
|
||||
arrivalTime = DateFormat('hh:mm').format(arrivalTime1);
|
||||
|
||||
for (int i = 0; i <= durationToRide; i++) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
progressTimerRideBegin = i / durationToRide;
|
||||
@@ -762,6 +772,7 @@ class MapPassengerController extends GetxController {
|
||||
? double.parse(box.read(BoxName.passengerWalletTotal))
|
||||
.toStringAsFixed(2)
|
||||
: '0',
|
||||
box.read(BoxName.email).toString(),
|
||||
];
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Order',
|
||||
@@ -1022,6 +1033,8 @@ class MapPassengerController extends GetxController {
|
||||
"order_id": rideId.toString(), // Convert to String
|
||||
"status": 'Cancel'
|
||||
});
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Cancel Trip', 'Trip Cancelled'.tr, driverToken, []);
|
||||
}
|
||||
rideConfirm = false;
|
||||
shouldFetch = false;
|
||||
@@ -1407,9 +1420,6 @@ class MapPassengerController extends GetxController {
|
||||
// });
|
||||
// }
|
||||
|
||||
late Timer markerReloadingTimer2;
|
||||
late Timer markerReloadingTimer1;
|
||||
late int duration1;
|
||||
void startMarkerReloading() {
|
||||
int reloadCount = 0;
|
||||
|
||||
@@ -1461,61 +1471,61 @@ class MapPassengerController extends GetxController {
|
||||
|
||||
getNearestDriverByPassengerLocation() async {
|
||||
if (polyLines.isEmpty || data.isEmpty) {
|
||||
if (rideConfirm == false) {
|
||||
double nearestDistance = double.infinity;
|
||||
if (dataCarsLocationByPassenger != 'failure') {
|
||||
if (dataCarsLocationByPassenger['message'].length > 0) {
|
||||
for (var i = 0;
|
||||
i < dataCarsLocationByPassenger['message'].length;
|
||||
i++) {
|
||||
var carLocation = dataCarsLocationByPassenger['message'][i];
|
||||
return null; // Early return if data is empty
|
||||
}
|
||||
if (!rideConfirm) {
|
||||
double nearestDistance = double.infinity;
|
||||
if (dataCarsLocationByPassenger != 'failure') {
|
||||
if (dataCarsLocationByPassenger['message'].length > 0) {
|
||||
for (var i = 0;
|
||||
i < dataCarsLocationByPassenger['message'].length;
|
||||
i++) {
|
||||
var carLocation = dataCarsLocationByPassenger['message'][i];
|
||||
|
||||
// }
|
||||
// isloading = true;
|
||||
// }
|
||||
// isloading = true;
|
||||
update();
|
||||
// Make API request to get exact distance and duration
|
||||
String apiUrl =
|
||||
'${AppLink.googleMapsLink}distancematrix/json?destinations=${carLocation['latitude']},${carLocation['longitude']}&origins=${passengerLocation.latitude},${passengerLocation.longitude}&units=metric&key=${AK.mapAPIKEY}';
|
||||
var response = await CRUD().getGoogleApi(link: apiUrl, payload: {});
|
||||
if (response['status'] == "OK") {
|
||||
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'];
|
||||
|
||||
durationFromDriverToPassenger =
|
||||
Duration(seconds: duration1.toInt());
|
||||
newTime1 = currentTime.add(durationFromDriverToPassenger);
|
||||
timeFromDriverToPassenger =
|
||||
newTime1.add(Duration(minutes: 2.toInt()));
|
||||
durationByPassenger =
|
||||
data['rows'][0]['elements'][0]['duration']['text'];
|
||||
update();
|
||||
// Make API request to get exact distance and duration
|
||||
String apiUrl =
|
||||
'${AppLink.googleMapsLink}distancematrix/json?destinations=${carLocation['latitude']},${carLocation['longitude']}&origins=${passengerLocation.latitude},${passengerLocation.longitude}&units=metric&key=${AK.mapAPIKEY}';
|
||||
var response =
|
||||
await CRUD().getGoogleApi(link: apiUrl, payload: {});
|
||||
if (response['status'] == "OK") {
|
||||
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'];
|
||||
if (distance1 < nearestDistance) {
|
||||
nearestDistance = distance1.toDouble();
|
||||
|
||||
durationFromDriverToPassenger =
|
||||
Duration(seconds: duration1.toInt());
|
||||
newTime1 = currentTime.add(durationFromDriverToPassenger);
|
||||
timeFromDriverToPassenger =
|
||||
newTime1.add(Duration(minutes: 2.toInt()));
|
||||
durationByPassenger =
|
||||
data['rows'][0]['elements'][0]['duration']['text'];
|
||||
nearestCar = CarLocation(
|
||||
distance: distance1.toDouble(),
|
||||
duration: duration1.toDouble(),
|
||||
id: carLocation['driver_id'],
|
||||
latitude: double.parse(carLocation['latitude']),
|
||||
longitude: double.parse(carLocation['longitude']),
|
||||
);
|
||||
// isloading = false;
|
||||
update();
|
||||
if (distance1 < nearestDistance) {
|
||||
nearestDistance = distance1.toDouble();
|
||||
|
||||
nearestCar = CarLocation(
|
||||
distance: distance1.toDouble(),
|
||||
duration: duration1.toDouble(),
|
||||
id: carLocation['driver_id'],
|
||||
latitude: double.parse(carLocation['latitude']),
|
||||
longitude: double.parse(carLocation['longitude']),
|
||||
);
|
||||
// isloading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the distance and duration as needed
|
||||
else {
|
||||
//print(
|
||||
// 'Failed to retrieve distance and duration: ${response['status']}');
|
||||
// Handle the failure case
|
||||
}
|
||||
// Handle the distance and duration as needed
|
||||
else {
|
||||
//print(
|
||||
// 'Failed to retrieve distance and duration: ${response['status']}');
|
||||
// Handle the failure case
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1537,7 +1547,8 @@ class MapPassengerController extends GetxController {
|
||||
driverCarsLocationToPassengerAfterApplied.last.longitude,
|
||||
);
|
||||
if (distance > 500) {
|
||||
cancelRide();
|
||||
isCancelRidePageShown = true;
|
||||
update();
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: 'The Driver Will be in your location soon .'.tr,
|
||||
|
||||
Reference in New Issue
Block a user