Skip to content

Conversation

@filiph
Copy link
Contributor

@filiph filiph commented May 12, 2025

This change introduces a new MapUsedAfterWidgetDisposedError that facilitates debugging when the user calls a method on GoogleMapsController after 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

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  1. 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

@filiph
Copy link
Contributor Author

filiph commented May 12, 2025

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.

@stuartmorgan-g
Copy link
Collaborator

From triage: Still waiting on resolution of #9227 first.

@Piinks
Copy link
Contributor

Piinks commented Sep 2, 2025

Skipping stale PR nudge per blocked PR. :)

@stuartmorgan-g
Copy link
Collaborator

Should be unblocked very shortly.

@stuartmorgan-g
Copy link
Collaborator

This is unblocked now.

FYI, the new file will need a fresh copy of the license header when you merge in main, as the format changed slightly.

@filiph filiph force-pushed the fix/missing-plugin-exception-43785 branch from 3b53dc2 to c3eac1e Compare October 8, 2025 07:56
@filiph
Copy link
Contributor Author

filiph commented Oct 8, 2025

I've rebased and updated the code. This is now ready for review.

@filiph filiph force-pushed the fix/missing-plugin-exception-43785 branch from 9f01e7a to 90ceed1 Compare October 9, 2025 06:25
/// 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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -1,3 +1,8 @@
## 2.13.2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New API is a minor version bump, per semver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@filiph
Copy link
Contributor Author

filiph commented Oct 23, 2025

Sorry for the delay. The custom error class is gone and I bumped to 2.14.0

Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stuartmorgan-g
Copy link
Collaborator

From triage: @filiph is this waiting on anything before it lands?

@filiph
Copy link
Contributor Author

filiph commented Nov 4, 2025

From triage: @filiph is this waiting on anything before it lands?

Not at all! It can land immediately.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 4, 2025
@auto-submit auto-submit bot merged commit 5cae9ca into flutter:main Nov 4, 2025
80 checks passed
CaoGiaHieu-dev added a commit to CaoGiaHieu-dev/packages that referenced this pull request Nov 5, 2025
* '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 027f2e410241 to e5d5c01850f2 (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 6f8abdd77820 to 027f2e410241 (26 revisions) (flutter#10335)
  [google_sign_in] Remove use of OCMock (flutter#10290)
  [interactive_media_ads] Pin iOS dependency maximum (flutter#10349)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: google_maps_flutter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[maps] MissingPluginException when calling methods on maps instance that has been torn down on the native side

3 participants