This commit is contained in:
Hamza-Ayed
2023-10-14 15:03:19 +03:00
parent c1e4c74356
commit 642820c55b
24 changed files with 191 additions and 218 deletions

View File

@@ -6,6 +6,7 @@ import '../../../constant/links.dart';
import '../../../main.dart';
import '../../functions/crud.dart';
import '../../functions/location_controller.dart';
import 'map_driver_controller.dart';
class HomeCaptainController extends GetxController {
bool isActive = false;
@@ -17,7 +18,6 @@ class HomeCaptainController extends GetxController {
void onButtonSelected() {
isActive = !isActive;
if (isActive) {
locationController.startLocationUpdates();
activeStartTime = DateTime.now();
@@ -58,6 +58,7 @@ class HomeCaptainController extends GetxController {
'token': box.read(BoxName.tokenDriver),
'captain_id': box.read(BoxName.driverID).toString()
}).then((value) => print('cccc'));
box.write(BoxName.statusDriverLocation, 'off');
super.onInit();
}

View File

@@ -13,7 +13,6 @@ import 'package:ride/views/Rate/rate_passenger.dart';
import '../../../constant/credential.dart';
import '../../../constant/links.dart';
import '../../../views/home/Captin/home_captin.dart';
import '../../functions/crud.dart';
class MapDriverController extends GetxController {
@@ -36,6 +35,7 @@ class MapDriverController extends GetxController {
late String durationToPassenger;
late String walletChecked;
late String direction;
late String status;
bool isPassengerInfoWindow = false;
bool isBtnRideBegin = false;
bool isRideFinished = false;
@@ -51,22 +51,39 @@ class MapDriverController extends GetxController {
GoogleMapController? mapController;
late LatLng myLocation;
late Timer timer;
void onMapCreated(GoogleMapController controller) {
LocationController locationController = Get.find<LocationController>();
myLocation = locationController.myLocation;
mapController = controller;
controller.getVisibleRegion();
controller.animateCamera(
CameraUpdate.newLatLng(myLocation),
CameraUpdate.newLatLngZoom(myLocation, 10),
);
update();
// Set up a timer or interval to trigger the marker update every 3 seconds.
Timer.periodic(const Duration(seconds: 3), (_) {
timer = Timer.periodic(const Duration(seconds: 3), (_) {
updateMarker();
});
}
void changeStatusDriver() {
status = 'On';
update();
}
takeSnapMap() {
mapController!.takeSnapshot();
}
@override
void dispose() {
mapController!.dispose();
super.dispose();
}
void checkIsDriverNearPassenger() async {
if (isDriverNearPassengerStart) {
Timer.periodic(const Duration(seconds: 3), (timer) {
@@ -78,17 +95,6 @@ class MapDriverController extends GetxController {
// Replace "passengerLat" and "passengerLng" with the actual passenger's location
String passengerLat = passengerLocation; // Set the passenger's latitude
String passengerLng = ""; // Set the passenger's longitude
// double distance = calculateDistance(
// double.parse(driverLat),
// double.parse(driverLng),
// double.parse(passengerLat),
// double.parse(passengerLng),
// );
// if (distance < 50) {
// print("Distance to passenger: $distance meters");
// }
});
}
}
@@ -166,6 +172,7 @@ class MapDriverController extends GetxController {
isPassengerInfoWindow = false;
isRideStarted = true;
isRideFinished = false;
box.write(BoxName.statusDriverLocation, 'on');
update();
await CRUD().post(link: AppLink.updateRides, payload: {
'id': rideId,
@@ -179,6 +186,7 @@ class MapDriverController extends GetxController {
void finishRideFromDriver() async {
isRideFinished = true;
isRideStarted = false;
box.write(BoxName.statusDriverLocation, 'off');
// changeRideToBeginToPassenger();
await CRUD().post(link: AppLink.updateRides, payload: {
'id': rideId,

View File

@@ -56,7 +56,7 @@ class MapPassengerController extends GetxController {
bool isMainBottomMenuMap = true;
double heightBottomSheetShown = 0;
double cashConfirmPageShown = 250;
late String driverId;
double widthMapTypeAndTraffic = 50;
double paymentPageShown = Get.height * .6;
late LatLng southwest;
@@ -77,7 +77,7 @@ class MapPassengerController extends GetxController {
int timeToPassengerFromDriverAfterApplied = 0;
Timer? timerToPassengerFromDriverAfterApplied;
bool rideTimerBegin = false;
late double progressTimerRideBegin;
double progressTimerRideBegin = 0;
int remainingTimeTimerRideBegin = 60;
late String stringRemainingTimeRideBegin;
@@ -175,23 +175,10 @@ class MapPassengerController extends GetxController {
update();
print('rideTimerBegin: $rideTimerBegin');
print('isRideFinished: $isRideFinished');
Get.to(() => RateCaptain());
// Get.defaultDialog(
// title: 'Ride Is Finished.'.tr,
// titleStyle: AppStyle.title,
// content: Text(
// 'Rate the Captain Please?'.tr,
// style: AppStyle.title,
// ),
// confirm: MyElevatedButton(
// title: 'Ok'.tr,
// onPressed: () {
//
// Get.back(); //todo make Rate page
// },
// ),
// barrierDismissible: false,
// );
Get.to(() => RateCaptainFromPassenger(), arguments: {
'driverId': driverId.toString(),
'rideId': rideId.toString(),
});
}
void getBeginRideFromDriver() async {
@@ -260,7 +247,7 @@ class MapPassengerController extends GetxController {
"time": DateTime.now().toString(),
"endtime": durationToAdd.toString(),
"price": totalPassenger.toString(),
"passenger_id": box.read(BoxName.pasengerID).toString(),
"passenger_id": box.read(BoxName.passengerID).toString(),
"driver_id": dataCarsLocationByPassenger['message'][carsOrder]
['driver_id']
.toString(),
@@ -280,7 +267,7 @@ class MapPassengerController extends GetxController {
duration.toString(),
distance.toString(),
dataCarsLocationByPassenger['message'][carsOrder]['id'].toString(),
box.read(BoxName.pasengerID).toString(),
box.read(BoxName.passengerID).toString(),
box.read(BoxName.name).toString(),
box.read(BoxName.tokenFCM).toString(),
box.read(BoxName.phone).toString(),
@@ -405,7 +392,10 @@ class MapPassengerController extends GetxController {
} else {
dataCarsLocationByPassenger = jsonDecode(res);
// print(dataCarsLocationByPassenger);
driverId = dataCarsLocationByPassenger['message'][carsOrder]
['driver_id']
.toString();
// print('driverId==============$driverId');
for (var i = 0;
i < dataCarsLocationByPassenger['message'].length;
i++) {
@@ -444,14 +434,14 @@ class MapPassengerController extends GetxController {
Future runEvery30SecondsUntilConditionMet() async {
// Calculate the duration of the trip in minutes.
double tripDurationInMinutes = duration1 / 60;
double tripDurationInMinutes = duration1 / 30;
int loopCount = tripDurationInMinutes.ceil();
// If the trip duration is less than or equal to 50 minutes, then break the loop.
for (var i = 0; i < loopCount; i++) {
// Wait for 50 seconds.
await Future.delayed(const Duration(
seconds:
30)); // Run the `getDriverCarsLocationToPassengerAfterApplied()` function.
31)); // Run the `getDriverCarsLocationToPassengerAfterApplied()` function.
await getDriverCarsLocationToPassengerAfterApplied();
reloadMarkerDriverCarsLocationToPassengerAfterApplied();
}
@@ -483,6 +473,16 @@ class MapPassengerController extends GetxController {
} // Update the map with the new markers
}
restCounter() {
clearPlaces();
clearPolyline();
data = [];
rideConfirm = false;
shouldFetch = false;
timeToPassengerFromDriverAfterApplied = 0;
update();
}
Future cancelRide() async {
print(rideConfirm);
@@ -511,7 +511,7 @@ class MapPassengerController extends GetxController {
.driverID
.toString(), // Convert to String
"passengerID":
box.read(BoxName.pasengerID).toString(), // Convert to String
box.read(BoxName.passengerID).toString(), // Convert to String
"rideID": rideId.toString(), // Convert to String
"note": cancelNote
});

View File

@@ -18,7 +18,7 @@ class OrderHistoryController extends GetxController {
Future getOrderHistoryByPassenger() async {
var res = await CRUD().get(link: AppLink.getRides, payload: {
'passenger_id': box.read(BoxName.pasengerID).toString(),
'passenger_id': box.read(BoxName.passengerID).toString(),
});
if (res.toString() == 'failure') {
Get.snackbar('failure', 'message');