Skip to content

[google_maps_flutter] GoogleMapsFlutter plugin is executing callbacks after the widget is disposed #115283

@math1man

Description

@math1man

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listcustomer: huggsy (g3)has partial patchThere is a PR awaiting someone to take it across the finish linep: mapsGoogle Maps pluginpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions