Lyokone / flutterlocation

A Flutter plugin to easily handle realtime location in iOS and Android. Provides settings for optimizing performance or battery.
MIT License
1.11k stars 826 forks source link

fix: Can we get location from background service? #774

Open ash-hashtag opened 2 years ago

ash-hashtag commented 2 years ago

Description I'm trying to call Location().getLocation() from a service created by flutter_background_service plugin, since I want to get location even when app is terminated, and location plugin doesn't seem to support it

Expected behavior Somehow get location from background?

Steps To Reproduce create a service call Location().getLocation() inside the service

Tested on:

Other plugins:

flutter_background_service

Additional logs

E/flutter (17736): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Attempt to write to field 'io.flutter.plugin.common.MethodChannel$Result com.lyokone.location.FlutterLocation.getLocationResult' on a null object reference in method 'void com.lyokone.location.MethodCallHandlerImpl.onGetLocation(io.flutter.plugin.common.MethodChannel$Result)', null, java.lang.NullPointerException: Attempt to write to field 'io.flutter.plugin.common.MethodChannel$Result com.lyokone.location.FlutterLocation.getLocationResult' on a null object reference in method 'void com.lyokone.location.MethodCallHandlerImpl.onGetLocation(io.flutter.plugin.common.MethodChannel$Result)'
E/flutter (17736):      at com.lyokone.location.MethodCallHandlerImpl.onGetLocation(MethodCallHandlerImpl.java:117)
E/flutter (17736):      at com.lyokone.location.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:43)
E/flutter (17736):      at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (17736):      at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (17736):      at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (17736):      at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (17736):      at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (17736):      at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (17736):      at android.os.Looper.loopOnce(Looper.java:233)
E/flutter (17736):      at android.os.Looper.loop(Looper.java:334)
E/flutter (17736):      at android.app.ActivityThread.main(ActivityThread.java:8278)
E/flutter (17736):      at java.lang.reflect.Method.invoke(Native Method)
E/flutter (17736):      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582)
E/flutter (17736):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1065)
E/flutter (17736): )
jjazzme commented 2 years ago

same problem

Zingworks-Sachin commented 1 year ago

Same problem with me too. Did you guys get the solution?

Mr-Jeeva commented 1 year ago

same problem... any workaround??

Dimolll commented 1 year ago

same issue

diegohzea commented 1 year ago

same issue here, any workaround?