'Can't use Geolocator inside Workmanager's task in Flutter
I am trying to use either Geolocator.getCurrentLocation or Geolocator.checkPermission() inside Workmanager's task. Both of those calls raise the same exception:
MissingPluginException(No implementation found for method getCurrentPosition on channel flutter.baseflow.com/geolocator) - for getCurrentLocation.
And MissingPluginException(No implementation found for method checkPermission on channel flutter.baseflow.com/geolocator) for the checkPermission method.
Here is an example of the code
void callbackDispatcher() {
Workmanager().executeTask((taskName, inputData) async {
await Geolocator.checkPermission();
await Geolocator.getCurrentPosition();
});
}
There are few issues opened in GitHub repo of Geolocator, but there are no answers for them.
- https://github.com/Baseflow/flutter-geolocator/issues/1045
- https://github.com/Baseflow/flutter-geolocator/issues/1041
- https://github.com/Baseflow/flutter-geolocator/issues/1038
Any ideas on how I can solve this?
Solution 1:[1]
So, I found the solution for current problem. All I had to do is to replace the version of geolocator_android lib from ^3.1.6 with 3.1.5.
For some reason version 3.1.6 doesn't work as excepted.
geolocator: ^8.2.0
geolocator_android: 3.1.5
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
