Flutterlocation: "getLocation()" never returns

Created on 18 Apr 2019  ·  54Comments  ·  Source: Lyokone/flutterlocation

(First of all, thanks for your hardwork at this library)

Describe the bug
I am calling this method before calling "runApp(MyApp())" in my main method. I need this because my app needs a current known location at its very first frame:

_getLastKnownLocation() async {
  print("STARTING LOCATION SERVICE");
  var location = Location();
  location.changeSettings(accuracy: LocationAccuracy.POWERSAVE);
  if (!await location.hasPermission()) {
    await location.requestPermission();
  } 

  InMemoryDatabase.lastKnownLocation = await location.getLocation();
}

The call gets stuck on the last line of this method, never returning a proper position.

I am using library version 2.3.5 with flutter 1.2.1

Expected behavior
The method should return a position.

Tested on:

  • Android, 8.1.0 Motorola Moto G5S (real device)
bug inactive

Most helpful comment

I'm doing this, to avoid this bug

    var location = Location();
    location.changeSettings(accuracy: LocationAccuracy.LOW);

    LocationData position;

    bool hasPermission = await location.hasPermission() && await location.serviceEnabled();

    if (Platform.isAndroid) {
      if (!hasPermission) {
        hasPermission = await location.requestPermission() && await location.requestService();
      }
    } 

    if (hasPermission) {
      position = await location.getLocation().catchError(
        (e) => print("Unable to find your position."), 
        test: (e) => e is PlatformException
      ).catchError((e) => print("$e"));
    }

All 54 comments

i have same issue:

if i haven't enabled GPS when try to getLocation(), i confirm the request for enable it, but getLocation() never return, if i try again this work correctly

Hey ! I'll look into this over the weekend. Don't hesitate to use the authorisation process from the sample app in the mean time :)

Hi @Lyokone ,

Thanks for this wonderful plugin.
I am also facing the same issue.

Please fix or suggest or suggest an alternate meanwhile.

Thanks,

Hey ! Spent most of my time on the background location feature this weekend, so wasn't able to look into this. A simple workaround would be to use onLocationChanged() and to remove the listener once you get the first result.
Sorry for the delay in fixing this :/

Hey ! Spent most of my time on the background location feature this weekend, so wasn't able to look into this. A simple workaround would be to use onLocationChanged() and to remove the listener once you get the first result.
Sorry for the delay in fixing this :/

I've tested your sollution with await location.onLocationChanged().first and still blocking =(

Thanks for the great work, unfortunately having the same problem.

I upgraded from v1.2.0 which worked fine to v2.3.5 recently and started having this problem. Tried each version between 2.0.0 and 2.3.5 and also tried location.onLocationChanged().first but always get the same problem. Also downgrading below v2.0.0 isn't possible for my app now as I am building for iOS and android and version constraints keep me from going back.

Hey !

This is really strange since I'm having no problem on my end during testing and using the plugin in projects. Have you updated everything ? Can you launch adb logcat to see if you can get any other logs ?

Thanks for any help you can provide, here's what I hope is near the beginning of the relevant logs using adb logcat from when I start using getLocation:

04-26 11:39:19.199 862 2259 I ActivityManager: START u0 {act=com.google.android.gms.location.settings.CHECK_SETTINGS pkg=com.google.android.gms cmp=com.google.android.gms/com.google.android.location.settings.LocationSettingsCheckerActivity (has extras)} from uid 10039
04-26 11:39:19.200 646 646 D QCOM PowerHAL: LAUNCH HINT: ON
04-26 11:39:19.203 646 646 D QCOM PowerHAL: Activity launch hint handled
04-26 11:39:19.210 9926 9926 W ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@1d982e6
04-26 11:39:19.275 492 526 D SurfaceFlinger: duplicate layer name: changing com.google.android.gms/com.google.android.location.settings.LocationSettingsCheckerActivity to com.google.android.gms/com.google.android.location.settings.LocationSettingsCheckerActivity#1
04-26 11:39:19.309 646 646 D QCOM PowerHAL: LAUNCH HINT: OFF
04-26 11:39:19.314 862 896 I ActivityManager: Displayed com.google.android.gms/com.google.android.location.settings.LocationSettingsCheckerActivity: +90ms
04-26 11:39:20.299 1510 1838 V ImsSenderRxr: Read packet: 22 bytes
04-26 11:39:20.299 1510 1510 D ImsServiceSub: Message received: what = 2
04-26 11:39:20.299 1510 1510 D ImsServiceSub: handleImsStateChanged
04-26 11:39:20.302 1510 1510 D ImsServiceSub: sendBroadcastForDisconnected
04-26 11:39:20.302 1510 1839 I MmTelFeatureCompat: registrationDisconnected: resetting MMTEL capabilities.
04-26 11:39:20.302 1510 1839 I MmTelFeatureConnection: onDeregistered ::
04-26 11:39:20.303 2069 2088 I MmTelFeatureConnection: onDeregistered ::
04-26 11:39:20.316 2069 12927 I rcs : [PresencePublication] mIsVolteAvailable=false mIsVoWifiAvailable=false mIsVtAvailable=false mIsViWifiAvailable=false oldIsVolteAvailable=false oldIsVoWifiAvailable=false oldIsVtAvailable=false oldIsViWifiAvailable=false
04-26 11:39:20.382 1510 1510 D ServiceStateProvider: subId=1
04-26 11:39:20.383 2744 2744 I CarrierServices: [2] cpo.onReceive: Received SERVICE_STATE intent, clearing cached cell info
04-26 11:39:21.899 629 629 D audio_hw_primary: disable_audio_route: usecase(1) reset and update mixer path: low-latency-playback speaker
04-26 11:39:21.904 629 629 D hardware_info: hw_info_append_hw_type : device_name = speaker
04-26 11:39:21.904 629 629 D audio_hw_primary: disable_snd_device: snd_device(2: speaker)
04-26 11:39:25.066 1963 1967 E ANDR-PERF-OPTSHANDLER: Warning: Resource [2, 0] not supported for core 1. Instead use resource for core 0
04-26 11:39:25.066 629 3817 I ACDB-LOADER: ACDB AFE returned = -19
04-26 11:39:25.066 1963 1967 E ANDR-PERF-RESOURCEQS: Failed to apply optimization [2, 2, 0]
04-26 11:39:25.067 629 3817 D hardware_info: hw_info_append_hw_type : device_name = speaker
04-26 11:39:25.067 629 3817 D audio_hw_primary: enable_snd_device: snd_device(2: speaker)
04-26 11:39:25.067 629 3817 D audio_route: Apply path: speaker
04-26 11:39:25.067 629 3817 D audio_hw_primary: enable_audio_route: usecase(1) apply and update mixer path: low-latency-playback speaker
04-26 11:39:25.067 629 3817 D audio_route: Apply path: low-latency-playback speaker
04-26 11:39:25.070 9926 9949 D OpenGLRenderer: endAllActiveAnimators on 0x74fddb8e00 (RippleDrawable) with handle 0x74fdb1b420
04-26 11:39:25.092 8429 8429 I GeofencerStateMachine: sendQueryLocationOptIn
04-26 11:39:25.100 629 3817 D audio_hw_primary: out_write: retry previous failed cal level set
04-26 11:39:25.110 862 862 V SettingsProvider: Notifying for 0: content://settings/secure/location_providers_allowed
04-26 11:39:25.116 8429 12935 W Bundle : Key source expected Integer but value was a bnta. The default value 0 was returned.
04-26 11:39:25.116 8429 12935 W Bundle : Attempt to cast generated internal exception:
04-26 11:39:25.116 8429 12935 W Bundle : java.lang.ClassCastException: bnta cannot be cast to java.lang.Integer
04-26 11:39:25.116 8429 12935 W Bundle : at android.os.BaseBundle.getInt(BaseBundle.java:1036)
04-26 11:39:25.116 8429 12935 W Bundle : at android.content.Intent.getIntExtra(Intent.java:7380)
04-26 11:39:25.116 8429 12935 W Bundle : at com.google.android.location.settings.AriLoggingIntentOperation.onHandleIntent(:com.google.android.gms@[email protected] (100400-244116403):2)
04-26 11:39:25.116 8429 12935 W Bundle : at com.google.android.chimera.IntentOperation.onHandleIntent(:com.google.android.gms@[email protected] (100400-244116403):2)
04-26 11:39:25.116 8429 12935 W Bundle : at pjz.onHandleIntent(:com.google.android.gms@[email protected] (100400-244116403):4)
04-26 11:39:25.116 8429 12935 W Bundle : at dwl.run(:com.google.android.gms@[email protected] (100400-244116403):12)
04-26 11:39:25.116 8429 12935 W Bundle : at dwi.run(:com.google.android.gms@[email protected] (100400-244116403):9)
04-26 11:39:25.116 8429 12935 W Bundle : at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
04-26 11:39:25.116 8429 12935 W Bundle : at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
04-26 11:39:25.116 8429 12935 W Bundle : at java.lang.Thread.run(Thread.java:764)
04-26 11:39:25.120 862 896 I GnssLocationProvider: WakeLock acquired by sendMessage(ENABLE, 1, null)
04-26 11:39:25.114 862 862 V SettingsProvider: Notifying for 0: content://settings/secure/location_providers_allowed
04-26 11:39:25.125 862 897 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.location.PROVIDERS_CHANGED flg=0x10 } to com.google.android.apps.maps/com.google.android.apps.gmm.locationsharing.usr.LocationAvailabilityChecker$LocationProvidersChangedBroadcastReceiver
04-26 11:39:25.126 862 897 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.location.PROVIDERS_CHANGED flg=0x10 } to com.google.android.gms/com.google.android.location.internal.NlpNetworkProviderSettingsUpdateReceiver
04-26 11:39:25.126 862 897 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.location.PROVIDERS_CHANGED flg=0x10 } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
04-26 11:39:25.126 862 897 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.location.PROVIDERS_CHANGED flg=0x10 } to com.google.android.googlequicksearchbox/com.google.android.apps.gsa.broadcastreceiver.external.ExternalCommonBroadcastReceiver
04-26 11:39:25.130 640 640 W GnssHAL_GnssInterface: setCallback called more than once. Unexpected unless test.
04-26 11:39:25.133 862 896 D GnssLocationProvider: gnssSetCapabilitesCb: 119u
04-26 11:39:25.134 862 897 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.location.MODE_CHANGED flg=0x10 } to com.google.android.apps.maps/com.google.android.apps.gmm.locationsharing.usr.LocationAvailabilityChecker$LocationProvidersChangedBroadcastReceiver
04-26 11:39:25.134 862 897 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.location.MODE_CHANGED flg=0x10 } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
04-26 11:39:25.135 862 896 D GnssLocationProvider: gnssSetSystemInfoCb: yearOfHw=2016
04-26 11:39:25.135 640 640 E LocSvc_eng: loc_eng_init: log_eng state error: instance already initialized
04-26 11:39:25.135 640 640 E : open failed: /dev/mdm: No such file or directory
04-26 11:39:25.136 676 770 E PerMgrSrv: Permission denied, client UID 1021, peripehral modem
04-26 11:39:25.136 640 640 E PerMgrLib: modem registar fail
04-26 11:39:25.136 640 640 E PerMgrLib: GPS failed to register for modem
04-26 11:39:25.136 640 640 E LocSvc_LBSProxy: modemPowerVote:171]: Error: pm_client_register returned: -1
04-26 11:39:25.137 862 896 E GnssLocationProvider: Unable to initialize GNSS Xtra interface
04-26 11:39:25.137 640 640 E LocSvc_eng: loc_eng_agps_init: log_eng state error: agps instance already initialized
04-26 11:39:25.138 8429 8429 I GeofencerStateMachine: sendQueryLocationOptIn
04-26 11:39:25.140 8429 8597 I GeofencerStateMachine: Network location enabled.
04-26 11:39:25.142 862 862 V SettingsProvider: Notifying for 0: content://settings/global/network_recommendations_enabled
04-26 11:39:25.142 862 896 I GnssLocationProvider: WakeLock released by handleMessage(ENABLE, 1, null)
04-26 11:39:25.144 862 896 I GnssLocationProvider: WakeLock acquired by sendMessage(INJECT_NTP_TIME, 0, null)
04-26 11:39:25.144 862 896 I GnssLocationProvider: restartRequests
04-26 11:39:25.145 633 633 I NanohubHidlAdapter: Sending msg of type 0, size 18 to app 0x476f6f676c001004
04-26 11:39:25.147 8429 8429 I GeofencerStateMachine: sendQueryLocationOptIn
04-26 11:39:25.148 650 848 I nanohub : osLog: [NanoMinion] received MSG Type 0x31, Version 0, 14 bytes
04-26 11:39:25.150 862 896 I GnssLocationProvider: WakeLock released by handleMessage(INJECT_NTP_TIME, 0, null)
04-26 11:39:25.165 492 595 W SurfaceFlinger: Attempting to set client state on removed layer: com.google.android.gms/com.google.android.location.settings.LocationSettingsCheckerActivity#0
04-26 11:39:25.166 492 595 W SurfaceFlinger: Attempting to destroy on removed layer: com.google.android.gms/com.google.android.location.settings.LocationSettingsCheckerActivity#0
04-26 11:39:25.199 862 2244 W ActivityManager: Receiver with filter android.content.IntentFilter@878effa already registered for pid 12821, callerPackage is com.eventrentalsystems.www.erscontrolpanel
04-26 11:39:25.200 862 2189 W ActivityManager: Receiver with filter android.content.IntentFilter@9f889ab already registered for pid 12821, callerPackage is com.eventrentalsystems.www.erscontrolpanel
04-26 11:39:25.221 8429 8429 I NetRec : [2] aita.onChange: Starting service.
04-26 11:39:25.221 8429 8429 I NetRec : [2] aiwi.a: Now the active scorer.
04-26 11:39:25.222 8429 8593 W GCoreFlp: No location to return for getLastLocation()
04-26 11:39:25.250 8429 8605 W Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
04-26 11:39:25.260 862 897 W BroadcastQueue: Background execution not allowed: receiving Intent { act=com.google.android.location.internal.server.ACTION_RESTARTED flg=0x10 } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentInternalReceiver
04-26 11:39:25.317 492 526 W SurfaceFlinger: Attempting to set client state on removed layer: com.google.android.gms/com.google.android.location.settings.LocationSettingsCheckerActivity#1
04-26 11:39:25.317 492 526 W SurfaceFlinger: Attempting to destroy on removed layer: com.google.android.gms/com.google.android.location.settings.LocationSettingsCheckerActivity#1
04-26 11:39:25.359 8429 8593 W GCoreFlp: No location to return for getLastLocation()
04-26 11:39:25.377 8429 8593 I chatty : uid=10039(com.google.android.gms) FlpThread identical 2 lines
04-26 11:39:25.393 8429 8593 W GCoreFlp: No location to return for getLastLocation()
04-26 11:39:25.405 8429 8444 I .gms.persisten: Background concurrent copying GC freed 149654(7MB) AllocSpace objects, 26(1496KB) LOS objects, 49% free, 7MB/15MB, paused 95us total 149.287ms
04-26 11:39:25.407 8429 8593 W GCoreFlp: No location to return for getLastLocation()
04-26 11:39:25.417 8429 12939 I GCoreUlr: Starting service, intent=Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) }, extras=Bundle[{receiverAction=android.location.PROVIDERS_CHANGED}]
04-26 11:39:25.422 8429 8429 W ChimeraUtils: Non Chimera context
04-26 11:39:25.422 8429 8429 I chatty : uid=10039 com.google.android.gms.persistent identical 2 lines
04-26 11:39:25.422 8429 8429 W ChimeraUtils: Non Chimera context
04-26 11:39:25.469 8429 12888 I GCoreUlr: WorldUpdater received intent Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) } with receiverAction android.location.PROVIDERS_CHANGED
04-26 11:39:25.483 8429 12888 I GCoreUlr: WorldUpdater:android.location.PROVIDERS_CHANGED: Ensuring that reporting is stopped because of reasons: {account#-5#=[InactiveReason{mIdentifier=6, mName='ReportingNotEnabled'}, InactiveReason{mIdentifier=14, mName='HistoryNotEnabled'}]}
04-26 11:39:25.492 8429 12888 I GCoreUlr: Unbound from all signal providers.
04-26 11:39:25.492 8429 12717 I GCoreUlr: Successfully accounts update
04-26 11:39:25.510 8429 12717 I GCoreUlr: DispatchingService ignoring Intent { act=android.net.wifi.WIFI_STATE_CHANGED flg=0x4000010 (has extras) } because ULR inactive
04-26 11:39:25.518 8429 12935 I GCoreUlr: Starting service, intent=Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) }, extras=Bundle[{receiverAction=com.google.android.location.internal.server.ACTION_RESTARTED}]
04-26 11:39:25.537 8429 8429 I GCoreUlr: Unbound from all signal providers.
04-26 11:39:25.537 8429 12717 I GCoreUlr: Successfully accounts update
04-26 11:39:25.538 8429 8429 I GCoreUlr: Stopping handler for UlrDispSvcFast
04-26 11:39:25.568 8429 8429 I BeaconBle: Using BLE 'L' hardware layer
04-26 11:39:25.570 8429 8429 W Nearby : Bind call too late - someone already tried to get: interface bpqz [CONTEXT service_id=49 ]
04-26 11:39:25.589 8429 12717 I GCoreUlr: WorldUpdater received intent Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) } with receiverAction com.google.android.location.internal.server.ACTION_RESTARTED
04-26 11:39:25.601 8429 12717 I GCoreUlr: WorldUpdater:com.google.android.location.internal.server.ACTION_RESTARTED: Ensuring that reporting is stopped because of reasons: {account#-5#=[InactiveReason{mIdentifier=6, mName='ReportingNotEnabled'}, InactiveReason{mIdentifier=14, mName='HistoryNotEnabled'}]}
04-26 11:39:25.609 8429 12717 I GCoreUlr: Unbound from all signal providers.
04-26 11:39:25.610 8429 12888 I GCoreUlr: Successfully accounts update
04-26 11:39:25.622 8429 12717 I GCoreUlr: DispatchingService ignoring Intent { act=android.net.wifi.WIFI_STATE_CHANGED flg=0x4000010 (has extras) } because ULR inactive
04-26 11:39:25.634 8429 8429 I GCoreUlr: Unbound from all signal providers.
04-26 11:39:25.635 8429 8429 I GCoreUlr: Stopping handler for UlrDispSvcFast
04-26 11:39:25.635 8429 12640 I GCoreUlr: Successfully accounts update
04-26 11:39:28.333 629 629 D audio_hw_primary: disable_audio_route: usecase(1) reset and update mixer path: low-latency-playback speaker
04-26 11:39:28.337 629 629 D hardware_info: hw_info_append_hw_type : device_name = speaker
04-26 11:39:28.338 629 629 D audio_hw_primary: disable_snd_device: snd_device(2: speaker)
04-26 11:39:31.341 642 642 I /vendor/bin/hw/android.hardware.[email protected]: SRAM data: 2812000

Any news? I'm facing the same issue.

Hey, I've been unable to reproduce this error on my end for now. Is the
sample project working correctly for you ?

Le dim. 28 avr. 2019 à 16:29, Vito notifications@github.com a écrit :

Any news? I'm facing the same issue.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Lyokone/flutterlocation/issues/172#issuecomment-487384396,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA4COAXLH5HSZ67QUYWRJHTPSWYC3ANCNFSM4HG7JFAQ
.

I flashed a new custom ROM (Android Pie) on my phone, and now it works, and neither do I cannot reproduce the bug now. I'm going to try to reproduce it these days.

By the way, could it be a MIUI related issue?

Happy to know 😁
Can any other participant of the thread tell if they are using custom ROMs
?

Le dim. 28 avr. 2019 à 18:30, Vito notifications@github.com a écrit :

I flashed a new custom ROM (Android Pie) on my phone, and now it works,
and neither do I cannot reproduce the bug now. I'm going to try to
reproduce it these days.

By the way, could it be a MIUI related issue?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Lyokone/flutterlocation/issues/172#issuecomment-487394266,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA4COAXQ4YZTRT3ZITDVXTLPSXGI3ANCNFSM4HG7JFAQ
.

@Lyokone I use PIXEL 2 XL with original OS

I am using stock Xiami Mi A2 and stock Motorola Moto G5S.

I'm also using stock on the pixel 1, Android 9.

So a lot of different devices, Pixels especially should be fine. Is the sample app working properly for you ? Maybe the plugin isn't returning a proper error of something you would be missing.

Same issue on meizu M5 note w/ stock rom on the latest update

The app is not crashing but it is giving null on getLocation()
i tried it in galaxy j5

`LocationData _currentLocation;

Location _location;

Future getLoc() async {
_currentLocation = await _location.getLocation();

try {
  return _currentLocation.longitude;
} catch (e) {
  print("Error");
}
return 0.0;

}`

gradle.properties

android.enableJetifier=true android.useAndroidX=true org.gradle.jvmargs=-Xmx1536M

gradle.build
dependencies { classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.google.gms:google-services:4.2.0' }

E/flutter (26075): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The method 'getLocation' was called on null.
E/flutter (26075): Receiver: null
E/flutter (26075): Tried calling: getLocation()
E/flutter (26075): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
E/flutter (26075): #1 _NamazState.getLoc (package:flutter_quran/src/namaz_timing/NamazPage.dart:19:40)
E/flutter (26075):
E/flutter (26075): #2 _NamazState.initState (package:flutter_quran/src/namaz_timing/NamazPage.dart:33:5)
E/flutter (26075): #3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3846:58)
E/flutter (26075): #4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
E/flutter (26075): #5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
E/flutter (26075): #6 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
E/flutter (26075): #7 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
E/flutter (26075): #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
E/flutter (26075): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
E/flutter (26075): #10 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
E/flutter (26075): #11 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
E/flutter (26075): #12 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter (26075): #13 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
E/flutter (26075): #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
E/flutter (26075): #15 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
E/flutter (26075): #16 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
E/flutter (26075): #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
E/flutter (26075): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
E/flutter (26075): #19 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
E/flutter (26075): #20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
E/flutter (26075): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
E/flutter (26075): #22 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
E/flutter (26075): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
E/flutter (26075): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
E/flutter (26075): #25 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4876:14)
E/flutter (26075): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
E/flutter (26075): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
E/flutter (26075): #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
E/flutter (26075): #29 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
E/flutter (26075): #30 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter (26075): #31 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
E/flutter (26075): #32 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
E/flutter (26075): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
E/flutter (26075): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
E/flutter (26075): #35 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
E/flutter (26075): #36 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
E/flutter (26075): #37 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter (26075): #38 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3711:5)
E/flutter (26075): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2956:14)
E/flutter (26075): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:2759:12)
E/flutter (26075): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
E/flutter (26075): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
E/flutter (26075): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter (26075): #44 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3864:11)
E/flutter (26075): #45 Compone

@sarimk80 Location _location = Location()

Just to give another update on this issue, I took care of the problems by handling permissions another way before calling _location.getLocation();

Seems like the problem I was having was about handling permissions properly? Sorry I have not ran into the problem in the example app, as far as I can recall it worked fine.

I am also having this issue. Requesting permissions first, then on confirm of permissions, calling getLocation()

I'm having the same issue here. When I call _location= await Location().getLocation(); it show me a dialog about enabling the device location and it enable the location, but the function never return.

Call the future method in future builder this method work for me

` LocationData _currentLocation;

Location _location = Location();

Future getLoc() async {
_currentLocation = await _location.getLocation();

try {
  final coordinates = new Coordinates(
      _currentLocation.latitude, _currentLocation.longitude);
  var addresses =
      await Geocoder.local.findAddressesFromCoordinates(coordinates);
  var first = addresses.first;
  return first.locality;
} catch (e) { 
}
return "Earth";

}`

Try calling future with Future Builder

`body: FutureBuilder(

        future: getLoc(),

        builder: (BuildContext context, AsyncSnapshot snapshot_loc) {

          print(snapshot_loc.data);
          if (!snapshot_loc.hasData) {
            return Center(
              child: CircularProgressIndicator(),
            );
          } else {
         print(snapshot_loc.data)

        }`

I need to load my data out of a widget. I've tried to load using Future but it ins't work.

I figured out why it was not working for me. requestPermission was not getting called. After debugging it I found another plugin (device_calendar) was blindly returning true in their permissions handler even though it was for a different permission. Thus flutter was not calling the handler for location.

Here is a link to the related issue: https://github.com/builttoroam/flutter_plugins/issues/79

I figured out why it was not working for me. requestPermission was not getting called. After debugging it I found another plugin (device_calendar) was blindly returning true in their permissions handler even though it was for a different permission. Thus flutter was not calling the handler for location.

Here is a link to the related issue: builttoroam/flutter_plugins#79

Hey ! Thanks for finding that, I'll see if I can better isolate my requests to not get handled by other plugins methods !
Was wondering what It could be for quite some time now :/

I figured out why it was not working for me. requestPermission was not getting called. After debugging it I found another plugin (device_calendar) was blindly returning true in their permissions handler even though it was for a different permission. Thus flutter was not calling the handler for location.
Here is a link to the related issue: builttoroam/flutter_plugins#79

Hey ! Thanks for finding that, I'll see if I can better isolate my requests to not get handled by other plugins methods !
Was wondering what It could be for quite some time now :/

Really looking forward.

I figured out why it was not working for me. requestPermission was not getting called. After debugging it I found another plugin (device_calendar) was blindly returning true in their permissions handler even though it was for a different permission. Thus flutter was not calling the handler for location.
Here is a link to the related issue: builttoroam/flutter_plugins#79

Hey ! Thanks for finding that, I'll see if I can better isolate my requests to not get handled by other plugins methods !
Was wondering what It could be for quite some time now :/

Yhea it seems to be a builttoroam's package issue, can someone please fix it?

I figured out why it was not working for me. requestPermission was not getting called. After debugging it I found another plugin (device_calendar) was blindly returning true in their permissions handler even though it was for a different permission. Thus flutter was not calling the handler for location.
Here is a link to the related issue: builttoroam/flutter_plugins#79

Hey ! Thanks for finding that, I'll see if I can better isolate my requests to not get handled by other plugins methods !
Was wondering what It could be for quite some time now :/

I don't know that you can isolate your request. In the flutter engine it looks like it exits the loop after the first plugin that returns true. Thus if you have another plugin requesting the same permission and they get notified before you your plugin will not get called. Look here:
https://github.com/flutter/engine/blob/45f69ac471b47e95dfeef36e5e81597b05ed19f5/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java

`
@Override
public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

    for (RequestPermissionsResultListener listener : mRequestPermissionsResultListeners) {

        if (listener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {

            return true;

        }

    }

    return false;
}

`

I figured out why it was not working for me. requestPermission was not getting called. After debugging it I found another plugin (device_calendar) was blindly returning true in their permissions handler even though it was for a different permission. Thus flutter was not calling the handler for location.
Here is a link to the related issue: builttoroam/flutter_plugins#79

Hey ! Thanks for finding that, I'll see if I can better isolate my requests to not get handled by other plugins methods !
Was wondering what It could be for quite some time now :/

I don't know that you can isolate your request. In the flutter engine it looks like it exits the loop after the first plugin that returns true. Thus if you have another plugin requesting the same permission and they get notified before you your plugin will not get called. Look here:
https://github.com/flutter/engine/blob/45f69ac471b47e95dfeef36e5e81597b05ed19f5/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java

`
@override
public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

    for (RequestPermissionsResultListener listener : mRequestPermissionsResultListeners) {

        if (listener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {

            return true;

        }

    }

    return false;
}

`

This is really a bad news :(

Hey, any updte on this?

I'm doing this, to avoid this bug

    var location = Location();
    location.changeSettings(accuracy: LocationAccuracy.LOW);

    LocationData position;

    bool hasPermission = await location.hasPermission() && await location.serviceEnabled();

    if (Platform.isAndroid) {
      if (!hasPermission) {
        hasPermission = await location.requestPermission() && await location.requestService();
      }
    } 

    if (hasPermission) {
      position = await location.getLocation().catchError(
        (e) => print("Unable to find your position."), 
        test: (e) => e is PlatformException
      ).catchError((e) => print("$e"));
    }

I'm doing this, to avoid this bug

    var location = Location();
    location.changeSettings(accuracy: LocationAccuracy.LOW);

    LocationData position;

    bool hasPermission = await location.hasPermission() && await location.serviceEnabled();

    if (Platform.isAndroid) {
      if (!hasPermission) {
        hasPermission = await location.requestPermission() && await location.requestService();
      }
    } 

    if (hasPermission) {
      position = await location.getLocation().catchError(
        (e) => print("Unable to find your position."), 
        test: (e) => e is PlatformException
      ).catchError((e) => print("$e"));
    }

I'm going to try this code today. Thank you!

Same issue, getting
PlatformException (PlatformException(ERROR, Failed to get location., null))
on
currentLocation = await location.getLocation();
Flutter 1.5.4-hotfix.2 • channel stable
Dart 2.3.0

Thanks @xascis. I had the same issue and discovered that it was my power setting that made getLocation() requests unresponsive. I had accuracy set to LocationAccuracy.POWERSAVE, and setting it to LocationAccuracy.LOW solved the issue for me.

Info about PRIORITY_NO_POWER setting on android: https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest

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.

Any update on this?

Any update on this guys? Thanks in advance

Any update on this guys? Thanks in advance

For anyone looking for an update try location.changeSettings(accuracy: LocationAccuracy.LOW);
It worked for me.

@Banglemoose Using LocationAccuracy.LOW for me is a no. It forces me to open my wifi even if I am not connected to any network. Is there anyway to prevent it from asking for wifi accessibility?

Is there a solution ? version 2.3.5 continues with same problem

Hello , any news? we are also looking for a solution we want to make a routing app but we can not track our location

It seems that the repository is no longer maintained. I now use flutter-geolocator and it works fine.

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.

Sounds related to #239.

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.

I'm seeing this issue on iOS now.

I'm seeing this on IOS as well.

Same problem here in iOS and changing the accuracy to low doesn't work for me

For those who still having this issue I'm using this workaround:

  1. Use another package to check and ask for permission
  2. If permission granted then use this package

This works and is what I'm currently using in prodution. Let me know if this helps you in any way.

@pedromassango also have this solution in place for several Flutter apps but it's extremely poor. Seeing the issue on our iOS apps for Reach-Native.

@Lyokone do you have plans to use another package for permission requests?

Still the same issue I think I will use flutter-geolocator https://pub.dev/packages/geolocator

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LinusU picture LinusU  ·  3Comments

KingWu picture KingWu  ·  11Comments

zeienko-vitalii picture zeienko-vitalii  ·  7Comments

RomanJos picture RomanJos  ·  4Comments

giudon010 picture giudon010  ·  3Comments