flutter-mapbox-gl / maps

A Mapbox GL flutter package for creating custom maps
Other
1.04k stars 503 forks source link

add dispose guard #1323

Closed felix-ht closed 1 year ago

felix-ht commented 1 year ago

Add a better error to indicate that a MapboxMapController was used after is has been disposed. Closes https://github.com/flutter-mapbox-gl/maps/issues/1048

assemblethis commented 1 year ago

Very useful. Thanks.

I was getting the following error message:

MissingPluginException(No implementation found for method map#matchMapLanguageWithDeviceDefault on channel plugins.flutter.io/mapbox_maps_0)
#0      MethodChannel._invokeMethod
#1      MethodChannelMapboxGl.matchMapLanguageWithDeviceDefault

and now I'm getting:

════════ Exception caught by Flutter framework ═════════════════════════════════
The following StateError was thrown:
Bad state: This MapboxMapController has already been disposed. This happens if flutter disposes a MapboxMap and you try to use its Controller afterwards.

When the exception was thrown, this was the stack
#0      MapboxMapController._disposeGuard
#1      MapboxMapController.matchMapLanguageWithDeviceDefault
...

I'll try to review this PR once I get a more detailed understanding of what's going on with my own code.

felix-ht commented 1 year ago

@assemblethis yes this this error is intentional and indicates that you use the controller after you disposed the widget holding the map

assemblethis commented 1 year ago

That was exactly my issue, so it's resolved now. Thanks!

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.