Skip to content

Commit 100100e

Browse files
authored
[google_maps_flutter_web] Don't hang onMapCreated when tiles fail to load (flutter#13059)
The web plugin reported a map as ready (triggering `onMapCreated`) only on the first `tilesloaded` event. That event requires every visible tile to download, so a single stalled or failed tile request leaves `onMapCreated` pending forever. On CI, this hangs `projection_test`, `overlays_test`, and `marker_clustering_test` until `flutter drive` fails with an opaque `DriverError` after 20 minutes. Example CI failures: - https://ci.chromium.org/b/8669392206413648801 - https://ci.chromium.org/b/8669672566864354113 - Report the map as ready on the first `tilesloaded` or the first `idle` event once the map `<div>` is attached and has a non-zero size, when the projection and bounds are available. - Re-enable the tests skipped in flutter/packages#13047. Fixes flutter#193452
1 parent 5e3747e commit 100100e

7 files changed

Lines changed: 392 additions & 358 deletions

File tree

‎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.6.4+2
2+
3+
* Fixes `onMapCreated` never being called when a map tile request stalls or fails.
4+
15
## 0.6.4+1
26

37
* Fixes AdvancedMarker anchor handling.

‎packages/google_maps_flutter/google_maps_flutter_web/example/latest/integration_test/google_maps_controller_test.dart‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void main() {
3838
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
3939

4040
group('GoogleMapController', () {
41-
const mapId = 33930;
41+
var mapId = 33930;
4242
late GoogleMapController controller;
4343
late StreamController<MapEvent<Object?>> stream;
4444

@@ -49,7 +49,7 @@ void main() {
4949
MapConfiguration mapConfiguration = const MapConfiguration(),
5050
}) {
5151
return GoogleMapController(
52-
mapId: mapId,
52+
mapId: ++mapId,
5353
streamController: stream,
5454
widgetConfiguration: MapWidgetConfiguration(
5555
initialCameraPosition: initialCameraPosition,
@@ -248,6 +248,41 @@ void main() {
248248
expect(events[4], isA<CameraIdleEvent>());
249249
});
250250

251+
testWidgets('reports the map as ready on idle only once its div is laid out', (
252+
WidgetTester tester,
253+
) async {
254+
controller = createController()
255+
..debugSetOverrides(
256+
createMap: (_, _) => map,
257+
circles: circles,
258+
heatmaps: heatmaps,
259+
markers: markers,
260+
polygons: polygons,
261+
polylines: polylines,
262+
groundOverlays: groundOverlays,
263+
)
264+
..init();
265+
final readyEvents = <MapEvent<Object?>>[];
266+
final StreamSubscription<MapEvent<Object?>> subscription = stream.stream
267+
.where((MapEvent<Object?> event) => event is WebMapReadyEvent)
268+
.listen(readyEvents.add);
269+
addTearDown(subscription.cancel);
270+
271+
// The map div is not in the DOM yet: idle must not report readiness.
272+
gmaps.event.trigger(map, 'idle');
273+
await tester.pump();
274+
expect(readyEvents, isEmpty);
275+
276+
await tester.pumpWidget(
277+
Center(child: SizedBox(width: 100, height: 100, child: controller.widget)),
278+
);
279+
// The platform view is created asynchronously; wait for it to render.
280+
await tester.pumpAndSettle();
281+
gmaps.event.trigger(map, 'idle');
282+
await tester.pump();
283+
expect(readyEvents, hasLength(1));
284+
});
285+
251286
testWidgets('emits point of interest tap when click has placeId', (
252287
WidgetTester tester,
253288
) async {

‎packages/google_maps_flutter/google_maps_flutter_web/example/latest/integration_test/marker_clustering_test.dart‎

Lines changed: 133 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -23,152 +23,145 @@ void main() {
2323
const mapCenter = LatLng(20, 20);
2424
const initialCameraPosition = CameraPosition(target: mapCenter);
2525

26-
group(
27-
'MarkersController',
28-
() {
29-
testWidgets('Marker clustering', (WidgetTester tester) async {
30-
const testMapId = 33930;
31-
const clusterManagerId = ClusterManagerId('cluster 1');
32-
33-
final clusterManagers = <ClusterManager>{
34-
const ClusterManager(clusterManagerId: clusterManagerId),
35-
};
36-
37-
// Create the marker with clusterManagerId.
38-
final initialMarkers = <Marker>{
39-
const Marker(
40-
markerId: MarkerId('1'),
41-
position: mapCenter,
42-
clusterManagerId: clusterManagerId,
26+
group('MarkersController', () {
27+
testWidgets('Marker clustering', (WidgetTester tester) async {
28+
const testMapId = 33930;
29+
const clusterManagerId = ClusterManagerId('cluster 1');
30+
31+
final clusterManagers = <ClusterManager>{
32+
const ClusterManager(clusterManagerId: clusterManagerId),
33+
};
34+
35+
// Create the marker with clusterManagerId.
36+
final initialMarkers = <Marker>{
37+
const Marker(
38+
markerId: MarkerId('1'),
39+
position: mapCenter,
40+
clusterManagerId: clusterManagerId,
41+
),
42+
const Marker(
43+
markerId: MarkerId('2'),
44+
position: mapCenter,
45+
clusterManagerId: clusterManagerId,
46+
),
47+
};
48+
49+
final mapIdCompleter = Completer<int>();
50+
51+
await _pumpMap(
52+
tester,
53+
plugin.buildViewWithConfiguration(
54+
testMapId,
55+
(int id) => mapIdCompleter.complete(id),
56+
widgetConfiguration: const MapWidgetConfiguration(
57+
initialCameraPosition: initialCameraPosition,
58+
textDirection: TextDirection.ltr,
4359
),
44-
const Marker(
45-
markerId: MarkerId('2'),
60+
mapObjects: MapObjects(clusterManagers: clusterManagers, markers: initialMarkers),
61+
),
62+
);
63+
64+
final int mapId = await mapIdCompleter.future;
65+
expect(mapId, equals(testMapId));
66+
67+
final List<Cluster> clusters =
68+
await waitForValueMatchingPredicate<List<Cluster>>(
69+
tester,
70+
() async => inspector.getClusters(mapId: mapId, clusterManagerId: clusterManagerId),
71+
(List<Cluster> clusters) => clusters.isNotEmpty,
72+
) ??
73+
<Cluster>[];
74+
75+
expect(clusters.length, 1);
76+
expect(clusters[0].markerIds.length, 2);
77+
78+
// Copy only the first marker with null clusterManagerId.
79+
// This means that both markers should be removed from the cluster.
80+
final updatedMarkers = <Marker>{_copyMarkerWithClusterManagerId(initialMarkers.first, null)};
81+
82+
final markerUpdates = MarkerUpdates.from(initialMarkers, updatedMarkers);
83+
await plugin.updateMarkers(markerUpdates, mapId: mapId);
84+
85+
final List<Cluster> updatedClusters =
86+
await waitForValueMatchingPredicate<List<Cluster>>(
87+
tester,
88+
() async => inspector.getClusters(mapId: mapId, clusterManagerId: clusterManagerId),
89+
(List<Cluster> clusters) => clusters.isNotEmpty,
90+
) ??
91+
<Cluster>[];
92+
93+
expect(updatedClusters.length, 0);
94+
});
95+
96+
testWidgets('clusters render once per batched add', (WidgetTester tester) async {
97+
const clusterManagerId = ClusterManagerId('cluster 1');
98+
99+
final clusterManagers = <ClusterManager>{
100+
const ClusterManager(clusterManagerId: clusterManagerId),
101+
};
102+
103+
// Create the marker with clusterManagerId.
104+
final initialMarkers = <Marker>{
105+
for (var i = 0; i < 3; i++)
106+
Marker(
107+
markerId: MarkerId(i.toString()),
46108
position: mapCenter,
47109
clusterManagerId: clusterManagerId,
48110
),
49-
};
50-
51-
final mapIdCompleter = Completer<int>();
52-
53-
await _pumpMap(
54-
tester,
55-
plugin.buildViewWithConfiguration(
56-
testMapId,
57-
(int id) => mapIdCompleter.complete(id),
58-
widgetConfiguration: const MapWidgetConfiguration(
59-
initialCameraPosition: initialCameraPosition,
60-
textDirection: TextDirection.ltr,
61-
),
62-
mapObjects: MapObjects(clusterManagers: clusterManagers, markers: initialMarkers),
111+
};
112+
113+
final markersCluster1 = <Marker>{
114+
for (var i = 3; i < 7; i++)
115+
Marker(
116+
markerId: MarkerId(i.toString()),
117+
clusterManagerId: clusterManagerId,
118+
position: mapCenter,
63119
),
64-
);
65-
66-
final int mapId = await mapIdCompleter.future;
67-
expect(mapId, equals(testMapId));
68-
69-
final List<Cluster> clusters =
70-
await waitForValueMatchingPredicate<List<Cluster>>(
71-
tester,
72-
() async => inspector.getClusters(mapId: mapId, clusterManagerId: clusterManagerId),
73-
(List<Cluster> clusters) => clusters.isNotEmpty,
74-
) ??
75-
<Cluster>[];
76-
77-
expect(clusters.length, 1);
78-
expect(clusters[0].markerIds.length, 2);
79-
80-
// Copy only the first marker with null clusterManagerId.
81-
// This means that both markers should be removed from the cluster.
82-
final updatedMarkers = <Marker>{
83-
_copyMarkerWithClusterManagerId(initialMarkers.first, null),
84-
};
85-
86-
final markerUpdates = MarkerUpdates.from(initialMarkers, updatedMarkers);
87-
await plugin.updateMarkers(markerUpdates, mapId: mapId);
88-
89-
final List<Cluster> updatedClusters =
90-
await waitForValueMatchingPredicate<List<Cluster>>(
91-
tester,
92-
() async => inspector.getClusters(mapId: mapId, clusterManagerId: clusterManagerId),
93-
(List<Cluster> clusters) => clusters.isNotEmpty,
94-
) ??
95-
<Cluster>[];
96-
97-
expect(updatedClusters.length, 0);
98-
});
99-
100-
testWidgets('clusters render once per batched add', (WidgetTester tester) async {
101-
const clusterManagerId = ClusterManagerId('cluster 1');
102-
103-
final clusterManagers = <ClusterManager>{
104-
const ClusterManager(clusterManagerId: clusterManagerId),
105-
};
106-
107-
// Create the marker with clusterManagerId.
108-
final initialMarkers = <Marker>{
109-
for (var i = 0; i < 3; i++)
110-
Marker(
111-
markerId: MarkerId(i.toString()),
112-
position: mapCenter,
113-
clusterManagerId: clusterManagerId,
114-
),
115-
};
116-
117-
final markersCluster1 = <Marker>{
118-
for (var i = 3; i < 7; i++)
119-
Marker(
120-
markerId: MarkerId(i.toString()),
121-
clusterManagerId: clusterManagerId,
122-
position: mapCenter,
123-
),
124-
};
125-
126-
const testMapId = 33931;
127-
final events = StreamController<ClusteringEvent>();
128-
await _pumpMap(
129-
tester,
130-
plugin.buildViewWithConfiguration(
131-
testMapId,
132-
(int id) async {
133-
final StreamSubscription<ClusteringEvent>? subscription =
134-
(inspector as GoogleMapsInspectorWeb)
135-
.getClusteringEvents(mapId: testMapId, clusterManagerId: clusterManagerId)
136-
?.listen(events.add);
137-
138-
await plugin.updateMarkers(
139-
MarkerUpdates.from(initialMarkers, markersCluster1),
140-
mapId: testMapId,
141-
);
142-
143-
await Future<void>.delayed(const Duration(seconds: 1));
144-
await subscription?.cancel();
145-
await events.close();
146-
},
147-
widgetConfiguration: const MapWidgetConfiguration(
148-
initialCameraPosition: initialCameraPosition,
149-
textDirection: TextDirection.ltr,
150-
),
151-
mapObjects: MapObjects(clusterManagers: clusterManagers, markers: initialMarkers),
120+
};
121+
122+
const testMapId = 33931;
123+
final events = StreamController<ClusteringEvent>();
124+
await _pumpMap(
125+
tester,
126+
plugin.buildViewWithConfiguration(
127+
testMapId,
128+
(int id) async {
129+
final StreamSubscription<ClusteringEvent>? subscription =
130+
(inspector as GoogleMapsInspectorWeb)
131+
.getClusteringEvents(mapId: testMapId, clusterManagerId: clusterManagerId)
132+
?.listen(events.add);
133+
134+
await plugin.updateMarkers(
135+
MarkerUpdates.from(initialMarkers, markersCluster1),
136+
mapId: testMapId,
137+
);
138+
139+
await Future<void>.delayed(const Duration(seconds: 1));
140+
await subscription?.cancel();
141+
await events.close();
142+
},
143+
widgetConfiguration: const MapWidgetConfiguration(
144+
initialCameraPosition: initialCameraPosition,
145+
textDirection: TextDirection.ltr,
152146
),
153-
);
154-
155-
await expectLater(
156-
events.stream,
157-
emitsInAnyOrder([
158-
// Once per initial markers
159-
ClusteringEvent.begin,
160-
ClusteringEvent.end,
161-
// Once per new cluster
162-
ClusteringEvent.begin,
163-
ClusteringEvent.end,
164-
emitsDone,
165-
]),
166-
);
167-
});
168-
},
169-
// Flaky; see https://github.com/flutter/flutter/issues/193452
170-
skip: true,
171-
);
147+
mapObjects: MapObjects(clusterManagers: clusterManagers, markers: initialMarkers),
148+
),
149+
);
150+
151+
await expectLater(
152+
events.stream,
153+
emitsInAnyOrder([
154+
// Once per initial markers
155+
ClusteringEvent.begin,
156+
ClusteringEvent.end,
157+
// Once per new cluster
158+
ClusteringEvent.begin,
159+
ClusteringEvent.end,
160+
emitsDone,
161+
]),
162+
);
163+
});
164+
});
172165
}
173166

174167
// Repeatedly checks an asynchronous value against a test condition, waiting

0 commit comments

Comments
 (0)