J'obtiens l'erreur lorsque j'essaie d'obtenir l'emplacement dans le processus d'arrière-plan afin que le plug-in s'exécute dans un isolat séparé à l'aide de workmanager :
Failed to handle method call
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
Voici une trace de pile :
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): Failed to handle method call
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at com.google.android.gms.common.GooglePlayServicesUtilLight.isGooglePlayServicesAvailable(Unknown Source:12)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable(Unknown Source:5)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(Unknown Source:94)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable(Unknown Source:3)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(Unknown Source:93)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin.onMethodCall(GoogleApiAvailabilityPlugin.java:105)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#flutter.baseflow.com/google_api_availability/methods( 5234): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
J'ai créé un exemple d'application pour reproduire le problème : https://github.com/estevez-dev/sample_flutter_app
Il est préconfiguré pour fonctionner dans Gitpod. Appuyez simplement sur le bouton flottant pour démarrer la tâche en arrière-plan et vous obtiendrez une exception sur getCurrentPosition
.
Veuillez noter que l'application ne demandera pas d'autorisation de localisation, vous devez l'autoriser manuellement à partir des paramètres Android.
Version du plug-in : 5.3.0
Plate-forme:
Merci beaucoup d'avoir soumis ce problème ainsi que l'exemple de code détaillé et la description de l'erreur. Je vais étudier cela et essayer de fournir un correctif bientôt.
j'ai le même problème trouvez vous des solutions s'il vous plait
@walide67 , pas encore de solution.
@walide67 , pas encore de solution.
Avez-vous une solution pour suivre l'emplacement en arrière-plan ou au premier plan avec flutter
S'il vous plaît n'importe quelle aide parce que mon travail s'est arrêté
Ce problème devrait maintenant être résolu, nous avons publié un correctif pour le plugin google_api_availability
(dont dépend le geolocator
) résolvant l'exception du pointeur nul.
Puisque le google_api_availability
été publié en tant que correctif, il devrait être automatiquement récupéré, mais si vous voulez être sûr, veuillez mettre à jour vers la version 5.3.1 de geolocator
.
Je peux confirmer que ça marche ! Merci beaucoup!