This commit is contained in:
Hamza-Ayed
2024-03-25 17:15:13 +03:00
parent 5c702e7d06
commit 0f79b2d86b
20 changed files with 327 additions and 179 deletions

View File

@@ -87,7 +87,7 @@ class MapPassengerController extends GetxController {
List<LatLng> polylineCoordinates3 = [];
List<LatLng> polylineCoordinates4 = [];
List<List<LatLng>> polylineCoordinatesPointsAll = [];
List<LatLng> carsLocationByPassenger = [];
List carsLocationByPassenger = [];
List<LatLng> driverCarsLocationToPassengerAfterApplied = [];
BitmapDescriptor markerIcon = BitmapDescriptor.defaultMarker;
BitmapDescriptor tripIcon = BitmapDescriptor.defaultMarker;
@@ -144,7 +144,7 @@ class MapPassengerController extends GetxController {
double paymentPageShown = Get.height * .6;
late LatLng southwest;
late LatLng northeast;
List<CarLocationModel> carLocations = <CarLocationModel>[];
List<CarLocationModel> carLocationsModels = <CarLocationModel>[];
var dataCarsLocationByPassenger;
var datadriverCarsLocationToPassengerAfterApplied;
CarLocation? nearestCar;
@@ -840,6 +840,7 @@ class MapPassengerController extends GetxController {
: '0',
box.read(BoxName.email).toString(),
];
print(body);
FirebaseMessagesController().sendNotificationToDriverMapPolyline(
'Order',
jsonDecode(value)['message'].toString(),
@@ -847,7 +848,7 @@ class MapPassengerController extends GetxController {
.toString(),
body,
polylineCoordinates.toString());
// //print(dataCarsLocationByPassenger);
print(dataCarsLocationByPassenger);
// //print(dataCarsLocationByPassenger['message'][0]['token'].toString());
});
delayAndFetchRideStatus(rideId);
@@ -923,13 +924,46 @@ class MapPassengerController extends GetxController {
polylineCoordinates.toString());
}
delayAndFetchRideStatus(rideId);
delayAndFetchRideStatusForAllDriverAvailable(rideId);
update();
}
String statusRide = 'wait';
void delayAndFetchRideStatus(String rideId) {
Timer(const Duration(milliseconds: 200), () async {
if (shouldFetch) {
// //print('shouldFetch is =$shouldFetch');
var res = await CRUD()
.get(link: AppLink.getRideStatus, payload: {'id': rideId});
print(res);
var decod = jsonDecode(res);
print(' 0000000000000000000000000000000000000000000000000');
print(decod['data']);
if (decod['data'].toString() == 'Apply') {
// getUpdatedRideForDriverApply(rideId);
shouldFetch = false; // Stop further fetches
statusRide = 'Apply';
rideConfirm = false;
isSearchingWindow = false;
update();
startTimer();
} else if (decod['data'].toString() == 'Refused') {
// isDriversTokensSend = false;
if (isDriversTokensSend == false) {
confirmRideForAllDriverAvailable();
isDriversTokensSend = true;
}
} else if (isDriversTokensSend == false) {
delayAndFetchRideStatus(
rideId); // Repeat the delay and fetch operation
update();
}
}
});
}
void delayAndFetchRideStatusForAllDriverAvailable(String rideId) {
Timer(const Duration(milliseconds: 200), () async {
if (shouldFetch) {
// //print('shouldFetch is =$shouldFetch');
@@ -947,18 +981,7 @@ class MapPassengerController extends GetxController {
isSearchingWindow = false;
update();
startTimer();
} else if (decod['data'].toString() == 'Refused') {
// isDriversTokensSend = false;
if (isDriversTokensSend == false) {
confirmRideForAllDriverAvailable();
isDriversTokensSend = true;
}
}
// else if (isDriversTokensSend == false) {
// delayAndFetchRideStatus(
// rideId); // Repeat the delay and fetch operation
// update();
// }
}
});
}
@@ -1025,6 +1048,8 @@ class MapPassengerController extends GetxController {
}
late LatLng currentDriverLocation;
late double headingList;
Future getCarsLocationByPassenger() async {
// if (rideConfirm == false) {
carsLocationByPassenger = [];
@@ -1057,28 +1082,28 @@ class MapPassengerController extends GetxController {
carsLocationByPassenger.clear(); // Clear existing markers
late LatLng lastDriverLocation; // Initialize a variable for last location
// late LatLng lastDriverLocation; // Initialize a variable for last location
for (var i = 0; i < dataCarsLocationByPassenger['message'].length; i++) {
currentDriverLocation = LatLng(
double.parse(dataCarsLocationByPassenger['message'][i]['latitude']),
double.parse(dataCarsLocationByPassenger['message'][i]['longitude']),
);
var json = dataCarsLocationByPassenger['message'][i];
print(json);
CarLocationModel model = CarLocationModel.fromJson(json);
carLocationsModels.add(model);
// Update lastDriverLocation on each iteration
previousLocationOfDrivers = currentDriverLocation;
// currentDriverLocation = LatLng(
// double.parse(json['latitude']),
// double.parse(json['longitude']),
// );
// // headingList = double.parse(json['heading']);
carsLocationByPassenger.add(currentDriverLocation);
driversToken.add(dataCarsLocationByPassenger['message'][i]['token']);
// // Update lastDriverLocation on each iteration
// previousLocationOfDrivers = currentDriverLocation;
// carsLocationByPassenger.add(currentDriverLocation);
// // carsLocationByPassenger.add(headingList);
driversToken.add(json['token']);
}
// // Calculate rotation angle here (explained below)
// if (previousLocationOfDrivers != null) {
// angleDegrees = calculateAngleBetweenLocations(
// previousLocationOfDrivers, currentDriverLocation);
// // Use rotationAngle for marker rotation logic
// }
update();
}
}
@@ -1126,11 +1151,7 @@ class MapPassengerController extends GetxController {
for (var i = 0; i < driverCarsLocationToPassengerAfterApplied.length; i++) {
// }
// for (var item in driverCarsLocationToPassengerAfterApplied) {
double rotationCar = calculateAngleBetweenLocations(
LatLng(driverCarsLocationToPassengerAfterApplied[i - 1].latitude,
driverCarsLocationToPassengerAfterApplied[i - 1].longitude),
LatLng(driverCarsLocationToPassengerAfterApplied[i].latitude,
driverCarsLocationToPassengerAfterApplied[i].longitude));
final driverAcceptedMarker = Marker(
onTap: () => print('marker pressed'),
infoWindow: InfoWindow(
@@ -1141,7 +1162,8 @@ class MapPassengerController extends GetxController {
.toString()),
position: LatLng(driverCarsLocationToPassengerAfterApplied[i].latitude,
driverCarsLocationToPassengerAfterApplied[i].longitude),
rotation: rotationCar,
rotation: datadriverCarsLocationToPassengerAfterApplied['message'][0]
['heading'],
);
markers.add(driverAcceptedMarker);
update();
@@ -1624,12 +1646,12 @@ class MapPassengerController extends GetxController {
// print('currentLocationOfDrivers $currentLocationOfDrivers');
// }
final marker = Marker(
infoWindow: InfoWindow(title: '${item.latitude} minutes'),
markerId: MarkerId(durationToPassenger.toString()),
position: LatLng(item.latitude, item.longitude),
rotation: math.Random().nextDouble() * 360,
// Other properties for the marker, such as icon, info window, etc.
);
infoWindow: InfoWindow(title: '${item.latitude} minutes'),
markerId: MarkerId(durationToPassenger.toString()),
position: LatLng(item.latitude, item.longitude),
rotation: item.headingList
// Other properties for the marker, such as icon, info window, etc.
);
markers.add(marker);
update();
}