Skip to content

Commit cbaaad7

Browse files
ditmanEgor
authored andcommitted
[google_maps_flutter_web] Allow Markers with icon:null (flutter#2998)
1 parent 7d2086e commit cbaaad7

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.0+2
2+
3+
* Fix crash when converting Markers with icon explicitly set to null. [Issue](https://github.com/flutter/flutter/issues/64938).
4+
15
## 0.1.0+1
26

37
* Port e2e tests to use the new integration_test package.

packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -379,22 +379,25 @@ gmaps.MarkerOptions _markerOptionsFromMarker(
379379
Marker marker,
380380
gmaps.Marker currentMarker,
381381
) {
382-
final iconConfig = marker.icon.toJson() as List;
382+
final iconConfig = marker.icon?.toJson() as List;
383383
gmaps.Icon icon;
384384

385-
if (iconConfig[0] == 'fromAssetImage') {
386-
// iconConfig[2] contains the DPIs of the screen, but that information is
387-
// already encoded in the iconConfig[1]
388-
389-
icon = gmaps.Icon()
390-
..url = ui.webOnlyAssetManager.getAssetUrl(iconConfig[1]);
391-
392-
// iconConfig[3] may contain the [width, height] of the image, if passed!
393-
if (iconConfig.length >= 4 && iconConfig[3] != null) {
394-
final size = gmaps.Size(iconConfig[3][0], iconConfig[3][1]);
395-
icon
396-
..size = size
397-
..scaledSize = size;
385+
if (iconConfig != null) {
386+
if (iconConfig[0] == 'fromAssetImage') {
387+
assert(iconConfig.length >= 2);
388+
// iconConfig[2] contains the DPIs of the screen, but that information is
389+
// already encoded in the iconConfig[1]
390+
391+
icon = gmaps.Icon()
392+
..url = ui.webOnlyAssetManager.getAssetUrl(iconConfig[1]);
393+
394+
// iconConfig[3] may contain the [width, height] of the image, if passed!
395+
if (iconConfig.length >= 4 && iconConfig[3] != null) {
396+
final size = gmaps.Size(iconConfig[3][0], iconConfig[3][1]);
397+
icon
398+
..size = size
399+
..scaledSize = size;
400+
}
398401
}
399402
}
400403
return gmaps.MarkerOptions()

packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: google_maps_flutter_web
22
description: Web platform implementation of google_maps_flutter
33
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter
4-
version: 0.1.0+1
4+
version: 0.1.0+2
55

66
flutter:
77
plugin:

packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/markers_integration.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,17 @@ void main() {
9898

9999
expect(controller.markers[MarkerId('1')].infoWindowShown, isFalse);
100100
});
101+
102+
// https://github.com/flutter/flutter/issues/64938
103+
testWidgets('markers with icon:null work', (WidgetTester tester) async {
104+
final markers = {
105+
Marker(markerId: MarkerId('1'), icon: null),
106+
};
107+
108+
controller.addMarkers(markers);
109+
110+
expect(controller.markers.length, 1);
111+
expect(controller.markers[MarkerId('1')].marker.icon, isNull);
112+
});
101113
});
102114
}

0 commit comments

Comments
 (0)