mapbox / mapbox-maps-flutter

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

Fix crash due to lifecycle plugin. #478

Closed yunikkk closed 1 month ago

yunikkk commented 1 month ago

What does this pull request do?

Addresses the issue that was caused by the maps-lifecycle plugin being pulled to the build. Normally it was excluded from the flutter plugin explicitly here, and instead lifecycle methods onStart/onStop/onDestroy were called directly on the MapView.

However, other 3-party plugins could still bring the dependency. The plugin then crashes internally within ViewLifecycleOwner.

In this PR custom Lifecycle is implemented to manage MapView lifecycle calls, maps-lifecycle dependency is no longer excluded. Custom Lifecycle mirrors lifecycle of the hosting Flutter activity + additionally triggers MapView stop/destroy when widget is disposed but Flutter activity keeps living (that happens easily when MapView is added / removed from the screen).

What is the motivation and context behind this change?

Should fix multiple reported issues about java.lang.IllegalStateException: Please ensure that the hosting activity/fragment is a valid LifecycleOwner : #259, #152, #60, #291, #477, #308, #50.

Pull request checklist: