flutterlocation
flutterlocation copied to clipboard
onLocationChanged should throw an exception when location service is turned off while listening to it.
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:
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.
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.
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 ?
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?
That makes sense, I will see if I can add this, thanks for the suggestion :)
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!
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:
- Implement a LifecycleWatcher StackOverflow example
- Listen on
AppLifecycleState.resumed - If it's disbaled ask for enabling
- (optionally) Create a recursive call to force gps enabling before getting app access
Disclaimer: THIS IS ONLY TESTED ON ANDROID