This commit is contained in:
Hamza-Ayed
2024-09-08 18:25:13 +03:00
parent a40c6851ee
commit 3135187408
5 changed files with 62 additions and 77 deletions

View File

@@ -203,12 +203,6 @@ class LoginController extends GetxController {
}
}
goToMapPage() {
if (box.read(BoxName.email) != null) {
Get.offAll(() => const MapPagePassenger());
}
}
final location = Location();
// late PermissionStatus permissionGranted = PermissionStatus.denied;
@@ -246,10 +240,10 @@ class LoginController extends GetxController {
void onInit() async {
// permissionLocation = await Permission.locationWhenInUse.isGranted;
await getAppTester(AppInformation.appName);
if (isTest == 0 && box.read(BoxName.passengerID) != null) {
await loginUsingCredentials(
box.read(BoxName.passengerID), box.read(BoxName.email));
}
// if (isTest == 0 && box.read(BoxName.passengerID) != null) {
// // await loginUsingCredentials(
// // box.read(BoxName.passengerID), box.read(BoxName.email));
// }
super.onInit();
}
}

View File

@@ -2603,58 +2603,44 @@ class MapPassengerController extends GetxController {
Future<void> getLocation() async {
isLoading = true;
update();
try {
// Perform permission and service checks in parallel
final results = await Future.wait([
location.serviceEnabled(),
location.hasPermission(),
]);
bool serviceEnabled = results[0] as bool; // Cast to bool
PermissionStatus permissionGranted =
results[1] as PermissionStatus; // Cast to PermissionStatus
// Check if location services are enabled
bool serviceEnabled;
PermissionStatus permissionGranted;
// dialoge();
// Check if location services are enabled
serviceEnabled = await location.serviceEnabled();
if (!serviceEnabled) {
serviceEnabled = await location.requestService();
if (!serviceEnabled) {
serviceEnabled = await location.requestService();
if (!serviceEnabled) {
// Location services are still not enabled, handle the error
isLoading = false;
update();
return;
}
// Location services are still not enabled, handle the error
return;
}
// Check if the app has permission to access location
if (permissionGranted == PermissionStatus.denied) {
permissionGranted = await location.requestPermission();
if (permissionGranted != PermissionStatus.granted) {
// Location permission is still not granted, handle the error
isLoading = false;
update();
return;
}
}
// Request updated location with medium accuracy (faster)
LocationData _locationData = await location.getLocation();
passengerLocation =
LatLng(_locationData.latitude!, _locationData.longitude!);
// Process location data
getLocationArea(passengerLocation.latitude, passengerLocation.longitude);
newStartPointLocation = passengerLocation;
speed = _locationData.speed!;
// Update loading state
isLoading = false;
update();
} catch (e) {
// Handle exceptions (optional logging)
isLoading = false;
update();
}
// Check if the app has permission to access location
permissionGranted = await location.hasPermission();
if (permissionGranted == PermissionStatus.denied) {
permissionGranted = await location.requestPermission();
if (permissionGranted != PermissionStatus.granted) {
// Location permission is still not granted, handle the error
return;
}
}
// Configure location accuracy
// LocationAccuracy desiredAccuracy = LocationAccuracy.high;
// Get the current location
LocationData _locationData = await location.getLocation();
passengerLocation =
(_locationData.latitude != null && _locationData.longitude != null
? LatLng(_locationData.latitude!, _locationData.longitude!)
: null)!;
getLocationArea(passengerLocation.latitude, passengerLocation.longitude);
newStartPointLocation = passengerLocation;
speed = _locationData.speed!;
// //print location details
isLoading = false;
update();
}
LatLngBounds calculateBounds(