flutterlocation icon indicating copy to clipboard operation
flutterlocation copied to clipboard

onLocationChanged should throw an exception when location service is turned off while listening to it.

Open mbilalakmal opened this issue 4 years ago • 7 comments

Describe the bug Currently we can check whether location service is enabled or not before creating the onLocationChanged stream, but once it is created, there is no way to check whether location services are manually disabled by the user.

Expected behavior OnLocationChanged should throw a LocationServiceIsDisabled exception when the user turns off device location.That way it can be caught and a Dialog or Notification can be displayed to the user.

Tested on:

  • Android, API Level 29, real device (Motorola Moto G7 plus)

Other plugins:

mbilalakmal avatar Mar 14 '21 07:03 mbilalakmal

Yes, I have get the same problem. It is just like location switched automatically to WiFi (even if it isn't enabled) or if this plugin get a location cache.

neoacevedo avatar Mar 25 '21 15:03 neoacevedo

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.

stale[bot] avatar Jun 02 '21 17:06 stale[bot]

Thanks for the report, the current behaviour of restarting the onLocationChanged when the GPS gets back online seems fine. I could add a method to listen to GPS status, not sure if there is other packages doing that ?

Lyokone avatar Jun 05 '21 21:06 Lyokone

There is geolocator package that does this. Maybe an option can be provided like shouldThrowOnDisabled (or a more aptly name parameter) that lets the caller decide whether they want to be notified or not?

mbilalakmal avatar Jun 07 '21 16:06 mbilalakmal

That makes sense, I will see if I can add this, thanks for the suggestion :)

Lyokone avatar Jun 07 '21 17:06 Lyokone

I'm also looking for this feature if possible. The feature of getting an Exception within the same stream as location seems a good idea, removing the need to listen for another stream. If that's not possible, if the plugin could have a service status stream would be good too. Keep the good work and thx for the plugin!

guigzp avatar Jun 15 '21 01:06 guigzp

Any updates on this? It seems there is still no option to get notified if the location is turned off.

For others who have the same problem, my solution right now is:

  1. Implement a LifecycleWatcher StackOverflow example
  2. Listen on AppLifecycleState.resumed
  3. If it's disbaled ask for enabling
  4. (optionally) Create a recursive call to force gps enabling before getting app access

Disclaimer: THIS IS ONLY TESTED ON ANDROID

Koboo avatar Feb 15 '24 13:02 Koboo