10/14/1
This commit is contained in:
@@ -51,7 +51,7 @@ class LoginController extends GetxController {
|
||||
if (jsonDecoeded['status'] == 'success') {
|
||||
print(jsonDecoeded['data'][0]['verified']);
|
||||
if (jsonDecoeded['data'][0]['verified'] == 1) {
|
||||
box.write(BoxName.pasengerID, jsonDecoeded['data'][0]['id']);
|
||||
box.write(BoxName.passengerID, jsonDecoeded['data'][0]['id']);
|
||||
box.write(BoxName.email, jsonDecoeded['data'][0]['email']);
|
||||
box.write(BoxName.name, jsonDecoeded['data'][0]['first_name']);
|
||||
box.write(BoxName.phone, jsonDecoeded['data'][0]['phone']);
|
||||
@@ -59,11 +59,11 @@ class LoginController extends GetxController {
|
||||
Get.offAll(() => MapPage());
|
||||
isloading = false;
|
||||
update();
|
||||
print(box.read(BoxName.pasengerID).toString());
|
||||
print(box.read(BoxName.passengerID).toString());
|
||||
print(box.read(BoxName.tokenFCM));
|
||||
await CRUD().post(link: AppLink.addTokens, payload: {
|
||||
'token': box.read(BoxName.tokenFCM),
|
||||
'passengerID': box.read(BoxName.pasengerID).toString()
|
||||
'passengerID': box.read(BoxName.passengerID).toString()
|
||||
}).then((value) => print('cccc'));
|
||||
} else {
|
||||
isloading = false;
|
||||
|
||||
@@ -22,7 +22,7 @@ class TokenController extends GetxController {
|
||||
},
|
||||
body: {
|
||||
'token': box.read(BoxName.tokenFCM.toString()),
|
||||
'passengerID': box.read(BoxName.pasengerID).toString()
|
||||
'passengerID': box.read(BoxName.passengerID).toString()
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:location/location.dart';
|
||||
import 'package:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/links.dart';
|
||||
import 'package:ride/controller/functions/crud.dart';
|
||||
import 'package:ride/controller/home/captin/map_driver_controller.dart';
|
||||
import 'package:ride/main.dart';
|
||||
|
||||
// LocationController.dart
|
||||
@@ -26,13 +27,19 @@ class LocationController extends GetxController {
|
||||
|
||||
void startLocationUpdates() async {
|
||||
_locationTimer = Timer.periodic(const Duration(seconds: 20), (timer) async {
|
||||
await getLocation();
|
||||
try {
|
||||
await getLocation();
|
||||
|
||||
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
|
||||
'driver_id': box.read(BoxName.driverID).toString(),
|
||||
'latitude': myLocation.latitude.toString(),
|
||||
'longitude': myLocation.longitude.toString(),
|
||||
});
|
||||
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
|
||||
'driver_id': box.read(BoxName.driverID).toString(),
|
||||
'latitude': myLocation.latitude.toString(),
|
||||
'longitude': myLocation.longitude.toString(),
|
||||
'status': box.read(BoxName.statusDriverLocation).toString()
|
||||
});
|
||||
} catch (e) {
|
||||
// Handle the error gracefully
|
||||
print('Error during location updates: $e');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class LogOut {
|
||||
box.remove(BoxName.email);
|
||||
box.remove(BoxName.lang);
|
||||
box.remove(BoxName.name);
|
||||
box.remove(BoxName.pasengerID);
|
||||
box.remove(BoxName.passengerID);
|
||||
box.remove(BoxName.phone);
|
||||
box.remove(BoxName.tokenFCM);
|
||||
box.remove(BoxName.tokens);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -37,7 +37,7 @@ class PaymentController extends GetxController {
|
||||
|
||||
await CRUD().get(
|
||||
link: AppLink.getWalletByPassenger,
|
||||
payload: {'passenger_id': box.read(BoxName.pasengerID)}).then((value) {
|
||||
payload: {'passenger_id': box.read(BoxName.passengerID)}).then((value) {
|
||||
box.write(BoxName.passengerWalletTotal,
|
||||
jsonDecode(value)['message'][0]['total'].toString());
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ class ProfileController extends GetxController {
|
||||
isloading = true;
|
||||
update();
|
||||
var res = await CRUD().get(link: AppLink.getprofile, payload: {
|
||||
'id': box.read(BoxName.pasengerID).toString(),
|
||||
'id': box.read(BoxName.passengerID).toString(),
|
||||
});
|
||||
|
||||
if (res.toString() == 'failure') {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/colors.dart';
|
||||
import 'package:ride/constant/links.dart';
|
||||
import 'package:ride/constant/style.dart';
|
||||
import 'package:ride/controller/functions/crud.dart';
|
||||
@@ -11,20 +10,18 @@ import 'package:ride/views/home/Captin/home_captin.dart';
|
||||
import 'package:ride/views/home/map_page.dart';
|
||||
import 'package:ride/views/widgets/elevated_btn.dart';
|
||||
|
||||
class RatePassengerController extends GetxController {
|
||||
class RateController extends GetxController {
|
||||
double selectedRateItemId = -1;
|
||||
TextEditingController comment = TextEditingController();
|
||||
late String rideId, passengerId, driverId;
|
||||
String? rideId, passengerId, driverId;
|
||||
late GlobalKey<FormState> formKey;
|
||||
@override
|
||||
void onInit() {
|
||||
if (box.read(BoxName.driverID).toString() != '' ||
|
||||
box.read(BoxName.driverID).toString() != null) {
|
||||
passengerId = Get.arguments['passengerId'];
|
||||
rideId = Get.arguments['rideId'];
|
||||
} else {
|
||||
driverId = Get.arguments['driverId'];
|
||||
rideId = Get.find<MapPassengerController>().rideId;
|
||||
}
|
||||
formKey = GlobalKey<FormState>();
|
||||
passengerId = Get.arguments['passengerId'];
|
||||
rideId = Get.arguments['rideId'];
|
||||
driverId = Get.arguments['driverId'];
|
||||
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@@ -47,9 +44,8 @@ class RatePassengerController extends GetxController {
|
||||
'rideId': rideId,
|
||||
'rating': selectedRateItemId.toString(),
|
||||
'comment': comment.text,
|
||||
}).then((value) {
|
||||
Get.offAll(const HomeCaptain());
|
||||
});
|
||||
Get.offAll(const HomeCaptain());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,12 +58,13 @@ class RatePassengerController extends GetxController {
|
||||
confirm: MyElevatedButton(title: 'Ok', onPressed: () => Get.back()));
|
||||
} else {
|
||||
await CRUD().post(link: AppLink.addRateToDriver, payload: {
|
||||
'passenger_id': box.read(BoxName.pasengerID).toString(),
|
||||
'driverID': driverId,
|
||||
'rideId': rideId,
|
||||
'passenger_id': box.read(BoxName.passengerID).toString(),
|
||||
'driver_id': driverId,
|
||||
'ride_id': rideId,
|
||||
'rating': selectedRateItemId.toString(),
|
||||
'comment': comment.text,
|
||||
}).then((value) {
|
||||
Get.find<MapPassengerController>().restCounter();
|
||||
Get.offAll(const MapPage());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user