mapbox / mapbox-maps-flutter

Interactive, thoroughly customizable maps for Flutter powered by Mapbox Maps SDK
https://www.mapbox.com/mobile-maps-sdk
Other
289 stars 119 forks source link

Mapbox plugin throws IllegalStateException #152

Closed Yczar closed 7 months ago

Yczar commented 1 year ago

I'm trying to integrate the Mapbox maps plugin into my Flutter app, but I'm encountering an IllegalStateException when the map is displayed. Here's the error message:

Shutting down VM
E/AndroidRuntime(17194): FATAL EXCEPTION: main
E/AndroidRuntime(17194): Process: com.example.verygoodcore.navigation, PID: 17194
E/AndroidRuntime(17194): java.lang.IllegalStateException: Please ensure that the hosting activity/fragment is a valid LifecycleOwner
E/AndroidRuntime(17194):    at com.mapbox.maps.plugin.lifecycle.ViewLifecycleOwner.doOnAttached(ViewLifecycleOwner.kt:68)
E/AndroidRuntime(17194):    at com.mapbox.maps.plugin.lifecycle.ViewLifecycleOwner.<init>(ViewLifecycleOwner.kt:58)
E/AndroidRuntime(17194):    at com.mapbox.maps.plugin.lifecycle.MapboxLifecyclePluginImpl.registerLifecycleObserver(MapboxLifecyclePluginImpl.kt:30)
E/AndroidRuntime(17194):    at com.mapbox.maps.plugin.MapPluginRegistry.onAttachedToWindow(MapPluginRegistry.kt:173)
E/AndroidRuntime(17194):    at com.mapbox.maps.MapController.onAttachedToWindow$sdk_publicRelease(MapController.kt:346)
E/AndroidRuntime(17194):    at com.mapbox.maps.MapView.onAttachedToWindow(MapView.kt:129)
E/AndroidRuntime(17194):    at android.view.View.dispatchAttachedToWindow(View.java:21976)
E/AndroidRuntime(17194):    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4293)
5
E/AndroidRuntime(17194):    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4302)
E/AndroidRuntime(17194):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3443)
E/AndroidRuntime(17194):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2893)
E/AndroidRuntime(17194):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10445)
E/AndroidRuntime(17194):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1108)
E/AndroidRuntime(17194):    at android.view.Choreographer.doCallbacks(Choreographer.java:866)
E/AndroidRuntime(17194):    at android.view.Choreographer.doFrame(Choreographer.java:797)
E/AndroidRuntime(17194):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1092)
E/AndroidRuntime(17194):    at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(17194):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17194):    at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(17194):    at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(17194):    at android.app.ActivityThread.main(ActivityThread.java:8663)
E/AndroidRuntime(17194):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17194):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/AndroidRuntime(17194):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
I/Process (17194): Sending signal. PID: 17194 SIG: 9

I've made sure that the activity hosting the map view implements the LifecycleOwner interface, but the error still persists. I believe the issue is with the Mapbox maps plugin itself.

Steps to reproduce:

The Mapbox map should be displayed without any errors.

Actual result: The app crashes with the following the highlighted error message.

Environment:

Flutter version: 3.7.7 Mapbox maps plugin version: 0.4.2 Android device running API level 31

Flutter Doctor result:

czar@Ayotomides-MacBook-Pro navigation % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.7, on macOS 13.0 22A380 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.77.3)
[✓] Connected device (4 available)
[✓] HTTP Host Availability

• No issues found!
evil159 commented 7 months ago

Hi all, this issue should be fixed in https://github.com/mapbox/mapbox-maps-flutter/pull/478, feel free to reopen this ticket if you have any feedback!