question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

requestPermission call on location object does not return on first call

See original GitHub issue
_serviceEnabled = await location.serviceEnabled();
    if (!_serviceEnabled) {     
      _serviceEnabled = await location.requestService();     
      if (!_serviceEnabled) {
        return null;
      }
    }    
    _permissionGranted = await location.hasPermission();
    if (_permissionGranted == PermissionStatus.denied) {         
      _permissionGranted = await location.requestPermission();//this is where execution goes to die     
      if (_permissionGranted != PermissionStatus.granted) {        
        return null;
      }

Describe the bug I have the following code where I try to get location of the user. When this code is invoke for the very first time, the method requestPermission is where I get prompted on my phone for permission, when I press allowed, the method should return and execution continue.

It is worth noting that, if I do a hot reload during this perpetual wait, the request permission comes as granted (on this line _permissionGranted = await location.hasPermission()😉 without prompt.

Expected behavior When I allow permission on prompt, the program execution continue and the method requestMethod return a Future of PermissionStatus.

Tested on:

  • Android, API Level 23, real device (Huawei)
  • Not Tested On iOS

Following is my flutter doctor

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18362.535], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [√] Android Studio (version 3.6) [√] IntelliJ IDEA Community Edition (version 2018.1) [!] IntelliJ IDEA Ultimate Edition (version 2016.2) X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. X This install is older than the minimum recommended version of 2017.1.0. [√] VS Code, 32-bit edition (version 1.43.2) [√] Connected device (1 available)

! Doctor found issues in 1 category.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sajidbarchacommented, Apr 9, 2020

I also ran on API 28 PIXEL to same result.

I am using location: ^3.0.2

(Sorry about not putting the code in a code block above, for some reason, in a code block all the lines of code when being turned into one line)

0reactions
stale[bot]commented, Sep 23, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android M Permissions: onRequestPermissionsResult() not ...
If you call ActivityCompat.requestPermissions in a fragment, the onRequestPermissionsResult callback is called on the activity and not the fragment.
Read more >
Request location permissions - Android Developers
Overview · Build a calling app · Prevent caller ID spoofing · Telephony IDs. Wi-Fi. Request permission to access nearby Wi-Fi devices ...
Read more >
Access Google APIs | Google Play services - Google Developers
This guide shows how you can make API calls to any of the SDKs that are powered by Google Play services, including how...
Read more >
React Native geolocation: A complete tutorial - LogRocket Blog
However, Google does not recommend using the React Native API for ... returns the latitude in the object response called by the method ......
Read more >
Android Plugin Development Guide - Apache Cordova
One instance of a plugin object is created for the life of each WebView . Plugins are not instantiated until they are first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found