diff --git a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md index 1c4272849c05..0121042b1a02 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.0+2 + +* Fix crash when converting Markers with icon explicitly set to null. [Issue](https://github.com/flutter/flutter/issues/64938). + ## 0.1.0+1 * Port e2e tests to use the new integration_test package. diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart index 2eeaa0202995..0ec00871e676 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart @@ -379,22 +379,25 @@ gmaps.MarkerOptions _markerOptionsFromMarker( Marker marker, gmaps.Marker currentMarker, ) { - final iconConfig = marker.icon.toJson() as List; + final iconConfig = marker.icon?.toJson() as List; gmaps.Icon icon; - if (iconConfig[0] == 'fromAssetImage') { - // iconConfig[2] contains the DPIs of the screen, but that information is - // already encoded in the iconConfig[1] - - icon = gmaps.Icon() - ..url = ui.webOnlyAssetManager.getAssetUrl(iconConfig[1]); - - // iconConfig[3] may contain the [width, height] of the image, if passed! - if (iconConfig.length >= 4 && iconConfig[3] != null) { - final size = gmaps.Size(iconConfig[3][0], iconConfig[3][1]); - icon - ..size = size - ..scaledSize = size; + if (iconConfig != null) { + if (iconConfig[0] == 'fromAssetImage') { + assert(iconConfig.length >= 2); + // iconConfig[2] contains the DPIs of the screen, but that information is + // already encoded in the iconConfig[1] + + icon = gmaps.Icon() + ..url = ui.webOnlyAssetManager.getAssetUrl(iconConfig[1]); + + // iconConfig[3] may contain the [width, height] of the image, if passed! + if (iconConfig.length >= 4 && iconConfig[3] != null) { + final size = gmaps.Size(iconConfig[3][0], iconConfig[3][1]); + icon + ..size = size + ..scaledSize = size; + } } } return gmaps.MarkerOptions() diff --git a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml index e916f7aa6590..5a879c2b39b0 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -1,7 +1,7 @@ name: google_maps_flutter_web description: Web platform implementation of google_maps_flutter homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter -version: 0.1.0+1 +version: 0.1.0+2 flutter: plugin: diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/markers_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/markers_integration.dart index f447535668b9..76ddf017985c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/markers_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/markers_integration.dart @@ -98,5 +98,17 @@ void main() { expect(controller.markers[MarkerId('1')].infoWindowShown, isFalse); }); + + // https://github.com/flutter/flutter/issues/64938 + testWidgets('markers with icon:null work', (WidgetTester tester) async { + final markers = { + Marker(markerId: MarkerId('1'), icon: null), + }; + + controller.addMarkers(markers); + + expect(controller.markers.length, 1); + expect(controller.markers[MarkerId('1')].marker.icon, isNull); + }); }); }