[google_maps_flutter] Raise MapUsedAfterWidgetDisposedError when map controller used after map disposed#9242
Conversation
|
I was just made aware of #9227, which seems to fix the other aspect of flutter/flutter#43785. Happy to wait with this one until after that one lands. |
|
From triage: Still waiting on resolution of #9227 first. |
|
Skipping stale PR nudge per blocked PR. :) |
|
Should be unblocked very shortly. |
|
This is unblocked now. FYI, the new file will need a fresh copy of the license header when you merge in |
3b53dc2 to
c3eac1e
Compare
|
I've rebased and updated the code. This is now ready for review. |
9f01e7a to
90ceed1
Compare
| /// 1. Set the map controller field to `null` in your widget state's | ||
| /// `dispose()` method, or | ||
| /// 2. Check the [State.mounted] state before each use of the controller. | ||
| class MapUsedAfterWidgetDisposedError extends Error { |
There was a problem hiding this comment.
Is there a compelling reason to create a new Error type rather than use StateError with the same string used below as its message? A private helper method that returns that state error would still avoid code duplication, but without an extra class.
There was a problem hiding this comment.
I thought it nicer to have a separate class at the time, but I'm happy to just use StateError. I'll make the change.
| @@ -1,3 +1,8 @@ | |||
| ## 2.13.2 | |||
There was a problem hiding this comment.
New API is a minor version bump, per semver.
|
Sorry for the delay. The custom error class is gone and I bumped to 2.14.0 |
|
From triage: @filiph is this waiting on anything before it lands? |
Not at all! It can land immediately. |
* 'main' of https://github.com/CaoGiaHieu-dev/packages: Update packages/go_router/CHANGELOG.md [tool] Remove use of FETCH_HEAD (flutter#10357) Roll Flutter from 027f2e4 to e5d5c01 (73 revisions) (flutter#10362) [camera_platform_interface] Adds support for video stabilization to camera_platform_interface (flutter#10337) [google_maps_flutter] Raise `MapUsedAfterWidgetDisposedError` when map controller used after map disposed (flutter#9242) [pigeon] Replace containsKey with contains in Kotlin generator (flutter#10274) [video_player] Remove `package` in example `AndroidManifest.xml` file (flutter#10245) [flutter_svg] Fixes typo of `allowDrawingOutsideViewBox` in doc comments. (flutter#10256) [in_app_purchase] Remove use of Pigeon's Dart test generator (flutter#10328) [dependabot]: Bump com.squareup.okhttp3:okhttp from 5.1.0 to 5.3.0 in /packages/espresso/android (flutter#10348) Roll Flutter from 6f8abdd to 027f2e4 (26 revisions) (flutter#10335) [google_sign_in] Remove use of OCMock (flutter#10290) [interactive_media_ads] Pin iOS dependency maximum (flutter#10349)
… when map controller used after map disposed (flutter/packages#9242)
… when map controller used after map disposed (flutter/packages#9242)
… when map controller used after map disposed (flutter/packages#9242)
… when map controller used after map disposed (flutter/packages#9242)
… when map controller used after map disposed (flutter/packages#9242)
flutter/packages@3d926aa...f13bad3 2025-11-06 stuartmorgan@google.com Add Linux CODEOWNERS (flutter/packages#10235) 2025-11-06 stuartmorgan@google.com [ci] Add missing deps (flutter/packages#10366) 2025-11-05 65709676+huanghui1998hhh@users.noreply.github.com [go_router] ShellRoute will merge GoRouter's observers (flutter/packages#9436) 2025-11-05 dgyurov@gmail.com [pigeon] Update analyzer version (flutter/packages#10352) 2025-11-04 stuartmorgan@google.com [tool] Remove use of FETCH_HEAD (flutter/packages#10357) 2025-11-04 engine-flutter-autoroll@skia.org Roll Flutter from 027f2e4 to e5d5c01 (73 revisions) (flutter/packages#10362) 2025-11-04 8490712+ruicraveiro@users.noreply.github.com [camera_platform_interface] Adds support for video stabilization to camera_platform_interface (flutter/packages#10337) 2025-11-04 filiph@users.noreply.github.com [google_maps_flutter] Raise `MapUsedAfterWidgetDisposedError` when map controller used after map disposed (flutter/packages#9242) 2025-11-04 tarrinneal@gmail.com [pigeon] Replace containsKey with contains in Kotlin generator (flutter/packages#10274) 2025-11-04 116356835+AbdeMohlbi@users.noreply.github.com [video_player] Remove `package` in example `AndroidManifest.xml` file (flutter/packages#10245) 2025-11-04 me@nils.re [flutter_svg] Fixes typo of `allowDrawingOutsideViewBox` in doc comments. (flutter/packages#10256) 2025-11-04 stuartmorgan@google.com [in_app_purchase] Remove use of Pigeon's Dart test generator (flutter/packages#10328) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@3d926aa...f13bad3 2025-11-06 stuartmorgan@google.com Add Linux CODEOWNERS (flutter/packages#10235) 2025-11-06 stuartmorgan@google.com [ci] Add missing deps (flutter/packages#10366) 2025-11-05 65709676+huanghui1998hhh@users.noreply.github.com [go_router] ShellRoute will merge GoRouter's observers (flutter/packages#9436) 2025-11-05 dgyurov@gmail.com [pigeon] Update analyzer version (flutter/packages#10352) 2025-11-04 stuartmorgan@google.com [tool] Remove use of FETCH_HEAD (flutter/packages#10357) 2025-11-04 engine-flutter-autoroll@skia.org Roll Flutter from 027f2e4 to e5d5c01 (73 revisions) (flutter/packages#10362) 2025-11-04 8490712+ruicraveiro@users.noreply.github.com [camera_platform_interface] Adds support for video stabilization to camera_platform_interface (flutter/packages#10337) 2025-11-04 filiph@users.noreply.github.com [google_maps_flutter] Raise `MapUsedAfterWidgetDisposedError` when map controller used after map disposed (flutter/packages#9242) 2025-11-04 tarrinneal@gmail.com [pigeon] Replace containsKey with contains in Kotlin generator (flutter/packages#10274) 2025-11-04 116356835+AbdeMohlbi@users.noreply.github.com [video_player] Remove `package` in example `AndroidManifest.xml` file (flutter/packages#10245) 2025-11-04 me@nils.re [flutter_svg] Fixes typo of `allowDrawingOutsideViewBox` in doc comments. (flutter/packages#10256) 2025-11-04 stuartmorgan@google.com [in_app_purchase] Remove use of Pigeon's Dart test generator (flutter/packages#10328) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@3d926aa...f13bad3 2025-11-06 stuartmorgan@google.com Add Linux CODEOWNERS (flutter/packages#10235) 2025-11-06 stuartmorgan@google.com [ci] Add missing deps (flutter/packages#10366) 2025-11-05 65709676+huanghui1998hhh@users.noreply.github.com [go_router] ShellRoute will merge GoRouter's observers (flutter/packages#9436) 2025-11-05 dgyurov@gmail.com [pigeon] Update analyzer version (flutter/packages#10352) 2025-11-04 stuartmorgan@google.com [tool] Remove use of FETCH_HEAD (flutter/packages#10357) 2025-11-04 engine-flutter-autoroll@skia.org Roll Flutter from 027f2e4 to e5d5c01 (73 revisions) (flutter/packages#10362) 2025-11-04 8490712+ruicraveiro@users.noreply.github.com [camera_platform_interface] Adds support for video stabilization to camera_platform_interface (flutter/packages#10337) 2025-11-04 filiph@users.noreply.github.com [google_maps_flutter] Raise `MapUsedAfterWidgetDisposedError` when map controller used after map disposed (flutter/packages#9242) 2025-11-04 tarrinneal@gmail.com [pigeon] Replace containsKey with contains in Kotlin generator (flutter/packages#10274) 2025-11-04 116356835+AbdeMohlbi@users.noreply.github.com [video_player] Remove `package` in example `AndroidManifest.xml` file (flutter/packages#10245) 2025-11-04 me@nils.re [flutter_svg] Fixes typo of `allowDrawingOutsideViewBox` in doc comments. (flutter/packages#10256) 2025-11-04 stuartmorgan@google.com [in_app_purchase] Remove use of Pigeon's Dart test generator (flutter/packages#10328) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This change introduces a new
MapUsedAfterWidgetDisposedErrorthat facilitates debugging when the user calls a method onGoogleMapsControllerafter the associated map has been disposed. This replaces the previous behavior, which would sometimes throw a Platform-side error (MissingPluginException,Unable to establish connection on channel, etc.).Although technically non-breaking (we're replacing one error with another), this could be disruptive because the new error is raised eagerly and synchronously, as soon as a call is made. Before, the call could have potentially succeeded (?), and the error was asynchronous (and so, potentially, unawaited and ignored?).
Fixes flutter/flutter#43785.
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3