This commit is contained in:
Hamza-Ayed
2024-02-25 00:23:00 +03:00
parent a9f557ca83
commit b33e797f76
22 changed files with 368 additions and 159 deletions

View File

@@ -144,7 +144,7 @@ class HomeCaptainController extends GetxController {
update();
}
GoogleMapController? mapHomeCaptaiController;
late GoogleMapController mapHomeCaptaiController;
void onMapCreated(GoogleMapController controller) {
mapHomeCaptaiController = controller;
controller.getVisibleRegion();

View File

@@ -49,6 +49,8 @@ class MapDriverController extends GetxController {
late String totalCost;
late String distance;
late String name;
late String email;
late String totalPassenger;
late String phone;
late String rideId;
late String isHaveSteps;
@@ -69,7 +71,7 @@ class MapDriverController extends GetxController {
bool isdriverWaitTimeEnd = false;
bool isRideFinished = false;
bool isRideStarted = false;
double passengerInfoWindow = Get.height * .35;
double passengerInfoWindow = Get.height * .39;
double driverEndPage = 100;
double progress = 0;
double progressToPassenger = 0;
@@ -406,11 +408,11 @@ class MapDriverController extends GetxController {
}
print('passengerWalletBurc bef ${double.parse(passengerWalletBurc)}');
if (double.parse(passengerWalletBurc) < 0) {
print('passengerWalletBurc aft ${double.parse(passengerWalletBurc)}');
await CRUD().post(link: AppLink.addPassengersWallet, payload: {
'passenger_id': passengerId,
'balance': ((-1) * double.parse(passengerWalletBurc)).toString()
});
print('passengerWalletBurc aft ${double.parse(passengerWalletBurc)}');
}
Future.delayed(const Duration(milliseconds: 300));
FirebaseMessagesController().sendNotificationToPassengerToken(
@@ -718,6 +720,8 @@ class MapDriverController extends GetxController {
driverId = Get.arguments['driverId'];
distance = Get.arguments['Distance'];
name = Get.arguments['name'];
email = Get.arguments['email'];
totalPassenger = Get.arguments['totalPassenger'];
phone = Get.arguments['phone'];
walletChecked = Get.arguments['WalletChecked'];
tokenPassenger = Get.arguments['tokenPassenger'];

View File

@@ -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,

View File

@@ -23,7 +23,7 @@ class SplashScreenController extends GetxController
animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 7),
duration: const Duration(seconds: 4),
);
zoomInAnimation = Tween<double>(begin: 1.0, end: 1.5).animate(
@@ -45,7 +45,7 @@ class SplashScreenController extends GetxController
}
void startTimer() {
Timer(const Duration(seconds: 7), () {
Timer(const Duration(seconds: 4), () {
box.read(BoxName.onBoarding) == null
? Get.off(() => OnBoardingPage())
: box.read(BoxName.email) != null