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

@@ -14,6 +14,7 @@ import '../../../main.dart';
import '../../../views/home/my_wallet/walet_captain.dart';
import '../../../views/widgets/elevated_btn.dart';
import '../../functions/crud.dart';
import '../../functions/location_background_controller.dart';
import '../../functions/location_controller.dart';
import '../payment/captain_wallet_controller.dart';
@@ -39,6 +40,7 @@ class HomeCaptainController extends GetxController {
double widthMapTypeAndTraffic = 50;
// Inject the LocationController class
final locationController = Get.put(LocationController());
// final locationBackController = Get.put(LocationBackgroundController());
String formatDuration(Duration duration) {
String twoDigits(int n) => n.toString().padLeft(2, "0");
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
@@ -60,6 +62,7 @@ class HomeCaptainController extends GetxController {
if (isActive) {
if (double.parse(totalPoints) > -300) {
locationController.startLocationUpdates();
// locationBackController.startBackLocation();
activeStartTime = DateTime.now();
activeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
activeDuration = DateTime.now().difference(activeStartTime!);

View File

@@ -546,7 +546,10 @@ update ui for totla results
// }));
// }
// add wallet from passenger from driver
Get.to(() => RatePassenger());
Get.to(() => RatePassenger(), arguments: {
'passengerId': passengerId,
'rideId': rideId,
});
// Get.back();
}
@@ -653,22 +656,24 @@ update ui for totla results
final previousLocationOfDrivers = await sql.getCustomQuery('''SELECT
*
FROM
${TableName.carLocations}
${TableName.rideLocation}
WHERE
order_id = $rideId
ORDER BY
created_at DESC
LIMIT
1''');
print(previousLocationOfDrivers);
//get from sql
if (previousLocationOfDrivers.isNotEmpty) {
var lat = double.parse(previousLocationOfDrivers[0]['lat']);
var lng = double.parse(previousLocationOfDrivers[0]['lng']);
LatLng prev = LatLng(lat, lng);
recentAngelToMarker = calculateAngleBetweenLocations(prev, myLocation);
recentDistanceToDash =
calculateDistanceBetweenLocations(prev, myLocation);
print('recentAngelToMarker $recentAngelToMarker');
print('recentDistanceToDash $recentDistanceToDash');
}
sql.insertData({
'order_id': rideId,
@@ -683,7 +688,7 @@ LIMIT
position: locationController.myLocation,
draggable: true,
icon: carIcon,
rotation: recentAngelToMarker,
rotation: locationController.heading,
// infoWindow: const InfoWindow(
// title: 'Time',
// ),
@@ -724,7 +729,7 @@ LIMIT
void addCustomEndIcon() {
ImageConfiguration config = ImageConfiguration(
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
size: const Size(25, 25), devicePixelRatio: Get.pixelRatio);
BitmapDescriptor.fromAssetImage(config, 'assets/images/b.png',
mipmaps: false)
.then((value) {

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();
}