"location.getLocation()" sometimes doesn't work
Describe the bug
Sometimes when running this code:
await location.getLocation();
It doesn't continue to the next line and not even caught in a catch block
And I don't see anything in the logs.
UPDATE: It seems that sometimes the process just takes him so long for some reason. Why is that?
Versions: 5.0.3 6.0.1
Tested on:
- Android
(Android) when i use location.changeSettings(accuracy: LocationAccuracy.low); then its not working. I try lot but its not working.
Version 6.0.1
Future<(bool, LocationData?)> permissionWithLoction(bool initState) async { Location location = Location();
bool serviceEnabled; PermissionStatus permissionGranted; LocationData? locationData;
try { serviceEnabled = await location.serviceEnabled(); if (!serviceEnabled) { serviceEnabled = await location.requestService(); if (!serviceEnabled) { throw Exception(); } }
permissionGranted = await location.hasPermission();
if (permissionGranted == PermissionStatus.denied) {
permissionGranted = await location.requestPermission();
if (permissionGranted.name.toString() != "granted" &&
permissionGranted.name.toString() != "grantedLimited") {
permissionGranted = PermissionStatus.denied;
throw Exception();
} else {
await location.changeSettings(accuracy: LocationAccuracy.low);
locationData = await location.getLocation();
return (true, locationData);
}
} else {
location.changeSettings(accuracy: LocationAccuracy.low);
locationData = await location.getLocation();
return (true, locationData);
}
} catch (e) { await openAppSettings(initState); permissionGranted = PermissionStatus.denied; // return (permissionGranted, locationData); } return (false, locationData); }
Update: Now it doesn't work on iOS, I don't get any response and the async-await is stuck. Any idea? (iOS 17.5.1)
Version 6.0.2
@adiTzoref is 'precise location' turned off? Because that's an issue I noticed as well.
I opened a PR for this.
@adiTzoref is 'precise location' turned off? Because that's an issue I noticed as well.
I opened a PR for this.
No. Precise Location in settings is ON. But I think that also when I set it OFF it was the same.
Having similar issues, also with precise location ON. Seems it's something with calling the function too early (cubit's constructor), vs app's lifecycle or widget's initState/dispose which seems to work better
Edit: Indeed it seems related to await location.changeSettings. awaiting the changeSettings breaks something.