-
Notifications
You must be signed in to change notification settings - Fork 29.2k
Description
Internal: b/258950950
We're receiving error reports from production that indicate our GoogleMap
instances are performing callbacks like onCameraMove
and possibly even onMapCreated
are being called after the widget has been disposed by the Flutter framework. For most callbacks, the issue is that GoogleMapController
should disconnect its stream subscriptions in dispose()
. Right now, the listen()
calls are all fire-and-forget, which is problematic. The onMapCreated
issue can be resolved by adding the line
if (!mounted) return;
to the implementation of onPlatformViewCreated()
inside of GoogleMap
.
Another problem is that the lifetime of the GoogleMapController
is unclear. We retain the instance in a State object that builds the GoogleMap
widget, but I don't think that guarantees that the state object will only ever encounter a single controller. It would theoretically be possible for the GoogleMap
widget's state to be recreated without recreating our containing state. In this case, the old controller is leaked and invalid between the old widget being disposed and the new widget's onMapCreated
callback. Any calls to the controller in this window with throw an exception, and there's no easy way to check for that. A simple fix would be to expose either an isDisposed()
method on GoogleMapController
, or a listenable API on either the controller or the GoogleMap
widget to receive a callback when it gets disposed, so we can null out the reference.
Internal bug b/254913189