New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getLocation() never completes while another getLocation() call is pending #281
Comments
Hey ! The getLocation is in fact not supporting concurrent calls. |
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 news on this? |
Hey ! I did not had time to tackle this yet. Sorry for the delay :/ |
Hi, we had the exact same issue while trying to get users location multiple times. Our solution was to make a variable named lastLocation, where we would write users location every time that getLocation() has succeeded and set a timeout on getter with:
I hope it helps. |
Thanks for your help.You saved the day haha |
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. |
The getLocation() API does not support concurrent invocations and results in a future that never completes. It's preferable to avoid concurrent invocation but different parts of the app may be using the location plugin making it hard to avoid.
Here is a code sample demonstrating the issue. 'done' is never printed.
print('start');
final location1 = location.getLocation();
final location2 = location.getLocation();
await location1;
await location2;
print('done');
This behavior seems to be due to the fact that the plugin overwrites the method call result:
https://github.com/Lyokone/flutterlocation/blob/master/android/src/main/java/com/lyokone/location/LocationPlugin.java#L152
One workaround is to introduce a wrapper that serializes getLocation calls:
final lock = Lock();
Future getLocation() async =>
lock.synchronized(() async => location.getLocation());
Tested on Android 10 on a Pixel 3.
The text was updated successfully, but these errors were encountered: