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 825 forks source link

Attempt to write to field 'io.flutter.plugin.common.MethodChannel$Result com.lyokone.location.FlutterLocation.getLocationResult' on a null object reference #814

Open BrendanBasson4 opened 1 year ago

BrendanBasson4 commented 1 year ago

Description So I'm receiving a push notification that should then trigger the package to get the location. It works when the app is in the foreground but throws

Attempt to write to field 'io.flutter.plugin.common.MethodChannel$Result com.lyokone.location.FlutterLocation.getLocationResult' on a null object reference

when the app is in the background. Note: background mode is enabled.

Expected Behavior I want the location even when the app is in the background.

Steps To Reproduce

  1. Install Firebase messaging.
  2. Set the app in the background with location service in background mode.
  3. receive the background push notification.
  4. trigger getLocation function
  5. See Attempt to write to field 'io.flutter.plugin.common.MethodChannel$Result com.lyokone.location.FlutterLocation.getLocationResult' on a null object reference

Tested on:

Other plugins:

firebase_messaging: ^14.2.2

Additional logs

E/MethodChannel#lyokone/location( 6178): Failed to handle method call
E/MethodChannel#lyokone/location( 6178): java.lang.NullPointerException: Attempt to write to field 'io.flutter.plugin.common.MethodChannel$Result com.lyokone.location.FlutterLocation.getLocationResult' on a null object reference
E/MethodChannel#lyokone/location( 6178):    at com.lyokone.location.MethodCallHandlerImpl.onGetLocation(MethodCallHandlerImpl.java:117)
E/MethodChannel#lyokone/location( 6178):    at com.lyokone.location.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:43)
E/MethodChannel#lyokone/location( 6178):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/MethodChannel#lyokone/location( 6178):    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#lyokone/location( 6178):    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#lyokone/location( 6178):    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#lyokone/location( 6178):    at android.os.Handler.handleCallback(Handler.java:883)
E/MethodChannel#lyokone/location( 6178):    at android.os.Handler.dispatchMessage(Handler.java:100)
E/MethodChannel#lyokone/location( 6178):    at android.os.Looper.loop(Looper.java:214)
E/MethodChannel#lyokone/location( 6178):    at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#lyokone/location( 6178):    at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#lyokone/location( 6178):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#lyokone/location( 6178):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
LassazVegaz commented 1 year ago

I am getting the same

naiadelali commented 11 months ago

same here

davidalonsobadia commented 9 months ago

same here

fredyrx commented 8 months ago

same here

darul9061 commented 1 month ago

same here

RajaShanmugamJM commented 1 month ago

Any work arounds or solutions here?

spiderion commented 1 month ago

Same here. But I happens when I try to get the user location via push notification

I believe because I need to grant allTimeLocation permission and add the manifest permission too

sanaullah-dev commented 2 days ago

same here: 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)' at com.lyokone.location.MethodCallHandlerImpl.onGetLocation(MethodCallHandlerImpl.java:117) at com.lyokone.location.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:43) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:240) at android.os.Looper.loop(Looper.java:351) at android.app.ActivityThread.main(ActivityThread.java:8377) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013) )

sanaullah-dev commented 2 days ago

how we can get background location when notification method trigger.