You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It works just fine on mobile. On web, however, if permission is not granted it throws:
Error: User denied Geolocation
at Object.throw_ [as throw] (http://localhost:58334/dart_sdk.js:5057:11)
at html_geolocation_manager.HtmlGeolocationManager.new.getCurrentPosition (http://localhost:58334/packages/geolocator_web/src/html_geolocation_manager.dart.lib.js:37:23)
at getCurrentPosition.throw (<anonymous>)
at http://localhost:58334/dart_sdk.js:37450:38
at _RootZone.runBinary (http://localhost:58334/dart_sdk.js:37320:59)
at _FutureListener.thenAwait.handleError (http://localhost:58334/dart_sdk.js:32561:52)
at handleError (http://localhost:58334/dart_sdk.js:33094:51)
at Function._propagateToListeners (http://localhost:58334/dart_sdk.js:33120:17)
at _Future.new.[_completeError] (http://localhost:58334/dart_sdk.js:32970:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:58334/dart_sdk.js:33006:31)
at Object._microtaskLoop (http://localhost:58334/dart_sdk.js:37568:13)
at _startMicrotaskLoop (http://localhost:58334/dart_sdk.js:37574:13)
at http://localhost:58334/dart_sdk.js:33324:9
This is my code:
permission =awaitGeolocator.checkPermission();
if (permission ==LocationPermission.denied) {
permission =awaitGeolocator.requestPermission();
if (permission ==LocationPermission.denied) {
// Permissions are denied, next time you could try// requesting permissions again (this is also where// Android's shouldShowRequestPermissionRationale// returned true. According to Android guidelines// your App should show an explanatory UI now.bool? requestAgain =awaitgenerateAlertDialog(
context,
S.of(context).locationAccessDeniedTitle,
S.of(context).locationAccessDeniedMsg,
S.of(context).enableText,
() =>Navigator.pop(context, true),
leftBtnText:S.of(context).disableText,
leftBtnOnPressed: () =>Navigator.pop(context, false),
);
if (requestAgain!) permission =awaitGeolocator.requestPermission();
if (permission ==LocationPermission.denied) returnfalse;
}
}
if (permission ==LocationPermission.deniedForever) {
// Permissions are denied forever, handle appropriately.awaitgenerateAlertDialog(
context,
S.of(context).locationAccessDeniedForeverTitle,
S.of(context).locationAccessDeniedForeverMsg,
S.of(context).okText,
() =>Navigator.pop(context, false)
);
returnfalse;
}
// When we reach here, permissions are granted and we can// continue accessing the position of the device.await_getCoordinates();
@FRANIAZA thank you for posting this issue. The geolocator_web package indeed contained a bug where it didn't await a future when calling the requestPermission method.
I have just release version 2.0.5 of the geolocator_web package containing the bug fix. If you are depending on the geolocator package you might need to run flutter pub upgrade to make sure you pull in the latest version of the geolocator_web package.
It works just fine on mobile. On web, however, if permission is not granted it throws:
This is my code:
And this is the method _getCoordinates():
The problem is that the calls
are non blocking on web. So the call to
is made before permissions are granted/denied and if they are denied it throws error.
Am I doing it wrong or do these calls need to be blocking?
The text was updated successfully, but these errors were encountered: