Skip to content

[google_maps_flutter_web] Gracefully bypass HeatmapLayer when unsupported by Maps JS SDK#11782

Draft
jeffkwoh wants to merge 1 commit into
flutter:mainfrom
jeffkwoh:fix-web-heatmap-deprecation
Draft

[google_maps_flutter_web] Gracefully bypass HeatmapLayer when unsupported by Maps JS SDK#11782
jeffkwoh wants to merge 1 commit into
flutter:mainfrom
jeffkwoh:fix-web-heatmap-deprecation

Conversation

@jeffkwoh
Copy link
Copy Markdown
Contributor

This Pull Request resolves the critical runtime TypeError / NoSuchMethodError crash in the google_maps_flutter_web package caused by the Google Maps JavaScript API version 3.65 (May 2026) officially deprecating and removing the HeatmapLayer constructor (google.maps.visualization.HeatmapLayer).
Because google_maps_flutter_web historically attempted to instantiate this class directly on the web platform when adding a heatmap, the deprecation broke the web package examples and caused shapes_test.dart and shape_test.dart to crash, blocking the monorepo's web_platform_tests CI builders.

Proposed Resolution (Graceful Feature Detection)

Since Heatmap is a core shared platform interface API, we preserve its signature but implement dynamic, strongly-typed feature-detection at the web platform level:

  1. Phased Feature Detection (dom_window_extension.dart):
    Added safe, nullable @JS() interop properties on web.Window and JSObject to traverse namespaces sequentially:
    nullableGoogle $\rightarrow$ nullableMaps $\rightarrow$ nullableVisualization $\rightarrow$ nullableHeatmapLayer.
    This allows isHeatmapSupported() to safely check the loaded Maps JS SDK capabilities without throwing any nested property-access exceptions on undefined JS objects.
  2. Graceful Bypassing & Deduplication (heatmaps.dart):
    Shielded the addHeatmaps, changeHeatmaps, and removeHeatmaps methods in HeatmapsController to return early when isHeatmapSupported() is false. If unsupported, it logs a standard console warning via Flutter's debugPrint at most once per controller lifecycle using a private _warningLogged boolean flag, making all heatmap operations safe no-ops rather than runtime crashes.
  3. Dynamic Test Skipping (shape_test.dart & shapes_test.dart):
    Updated both integration test files to import the internal dom_window_extension.dart directly using implementation imports (// ignore: implementation_imports) to avoid code duplication. Both HeatmapController and HeatmapsController test groups are dynamically skipped via skip: !isHeatmapSupported() when running in browser environments loaded with SDK version 3.65+.

Fixes: flutter/flutter#187076

Pre-Review Checklist

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-assist bot 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

  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

@jeffkwoh jeffkwoh force-pushed the fix-web-heatmap-deprecation branch 6 times, most recently from 23a7434 to 47e6054 Compare May 26, 2026 09:24
…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.
@jeffkwoh jeffkwoh force-pushed the fix-web-heatmap-deprecation branch from 47e6054 to 180a1b6 Compare May 26, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[google_maps_flutter_web] HeatmapLayer runtime crash due to Google Maps JS SDK 3.65 deprecation/removal

1 participant