@@ -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