flutterlocation
flutterlocation copied to clipboard
fix: getLocation() freeze
Description if the user was disable location service on his phone, and just use requestService(), and he click ok, the app freeze at getLocation()
i use this code and check for PermissionStatus & requestService() before i use getLocation()
i use a fix for now by waiting for 1 sec before use getLocation() , and its work for now, maybe it have something with the time that the service needed to be active.
final PermissionStatus permissionStatus = await location.hasPermission();
log('serviceEnabled?');
final isServiceEnabled =await location.requestService();
log('serviceEnabled = $isServiceEnabled');
if (permissionStatus == PermissionStatus.granted && isServiceEnabled) {
log("Location Permission is granted");
try {
await Future.delayed(const Duration(seconds: 1));
final LocationData userLocationData = await location.getLocation();
log("userLocationData: $userLocationData");
Expected behavior get current user location
Steps To Reproduce
- Go to screen request location
- Click on ok to active location service
- app freeze with no error
Tested on:
- Android 11, real device
I am having the same issue. did you manage to solve it?
Can you try what happens when you use this code snippet
`try{ var loc = await location.getLocation().timeout(const Duration(seconds: 1)); }catch (e){
}`
Your app should not crash and freeze.
I am having the same issue. did you manage to solve it?
it work if i wait 1sec between location services activation and using getLocation()
Its just a workaround I think the reason is the time that the hardware take to start the service, and emit the location
I changed from using this package and moved to https://pub.dev/packages/permission_handler and my issue is solved
This package seems that is not maintained anymore https://pub.dev/packages/geolocator it's a good alternative