[google_maps_flutter_web] Gracefully bypass HeatmapLayer when unsupported by Maps JS SDK#11782
Draft
jeffkwoh wants to merge 1 commit into
Draft
[google_maps_flutter_web] Gracefully bypass HeatmapLayer when unsupported by Maps JS SDK#11782jeffkwoh wants to merge 1 commit into
jeffkwoh wants to merge 1 commit into
Conversation
23a7434 to
47e6054
Compare
…rted by Maps JS SDK Google Maps JS API version 3.65 deprecated and completely removed the HeatmapLayer constructor. To resolve the resulting runtime crashes on the web platform, this change implements a dynamic, strongly-typed feature-detection helper (isHeatmapSupported()) inside dom_window_extension.dart using standard nullable JS interop extensions. The HeatmapsController is shielded to return early and log a deduplicated warning message on the console via debugPrint at most once per controller lifecycle, making heatmap operations safe no-ops in 3.65+ environments. The web integration tests (shape_test.dart and shapes_test.dart) are updated to import dom_window_extension.dart directly and dynamically skip the heatmap controller test groups when the class is not supported by the browser environment.
47e6054 to
180a1b6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request resolves the critical runtime
TypeError/NoSuchMethodErrorcrash in thegoogle_maps_flutter_webpackage caused by the Google Maps JavaScript API version3.65(May 2026) officially deprecating and removing theHeatmapLayerconstructor (google.maps.visualization.HeatmapLayer).Because
google_maps_flutter_webhistorically attempted to instantiate this class directly on the web platform when adding a heatmap, the deprecation broke the web package examples and causedshapes_test.dartandshape_test.dartto crash, blocking the monorepo'sweb_platform_testsCI builders.Proposed Resolution (Graceful Feature Detection)
Since
Heatmapis a core shared platform interface API, we preserve its signature but implement dynamic, strongly-typed feature-detection at the web platform level:dom_window_extension.dart):Added safe, nullable
@JS()interop properties onweb.WindowandJSObjectto traverse namespaces sequentially:nullableGooglenullableMapsnullableVisualizationnullableHeatmapLayer.This allows
isHeatmapSupported()to safely check the loaded Maps JS SDK capabilities without throwing any nested property-access exceptions on undefined JS objects.heatmaps.dart):Shielded the
addHeatmaps,changeHeatmaps, andremoveHeatmapsmethods inHeatmapsControllerto return early whenisHeatmapSupported()isfalse. If unsupported, it logs a standard console warning via Flutter'sdebugPrintat most once per controller lifecycle using a private_warningLoggedboolean flag, making all heatmap operations safe no-ops rather than runtime crashes.shape_test.dart&shapes_test.dart):Updated both integration test files to import the internal
dom_window_extension.dartdirectly using implementation imports (// ignore: implementation_imports) to avoid code duplication. BothHeatmapControllerandHeatmapsControllertest groups are dynamically skipped viaskip: !isHeatmapSupported()when running in browser environments loaded with SDK version 3.65+.Fixes: flutter/flutter#187076
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.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