@@ -21,7 +21,7 @@ const CameraPosition _kInitialCameraPosition = CameraPosition(
2121 target: _kInitialMapCenter,
2222 zoom: _kInitialZoomLevel,
2323);
24- const String _kCloudMapId = '000000000000000' ; // Dummy map ID.
24+ const String _kMapId = '000000000000000' ; // Dummy map ID.
2525
2626// The tolerance value for floating-point comparisons in the tests.
2727// This value was selected as the minimum possible value that the test passes.
@@ -1366,16 +1366,107 @@ void main() {
13661366 }
13671367 });
13681368
1369- testWidgets ('testSetStyleMapId ' , (WidgetTester tester) async {
1369+ testWidgets ('advanced markers clustering ' , (WidgetTester tester) async {
13701370 final Key key = GlobalKey ();
1371+ const clusterManagersAmount = 2 ;
1372+ const markersPerClusterManager = 5 ;
1373+ final markers = < MarkerId , AdvancedMarker > {};
1374+ final clusterManagers = < ClusterManager > {};
1375+
1376+ for (var i = 0 ; i < clusterManagersAmount; i++ ) {
1377+ final clusterManagerId = ClusterManagerId ('cluster_manager_$i ' );
1378+ final clusterManager = ClusterManager (clusterManagerId: clusterManagerId);
1379+ clusterManagers.add (clusterManager);
1380+ }
1381+
1382+ for (final cm in clusterManagers) {
1383+ for (var i = 0 ; i < markersPerClusterManager; i++ ) {
1384+ final markerId = MarkerId ('${cm .clusterManagerId .value }_marker_$i ' );
1385+ final marker = AdvancedMarker (
1386+ markerId: markerId,
1387+ clusterManagerId: cm.clusterManagerId,
1388+ position: LatLng (
1389+ _kInitialMapCenter.latitude + i,
1390+ _kInitialMapCenter.longitude,
1391+ ),
1392+ );
1393+ markers[markerId] = marker;
1394+ }
1395+ }
1396+
1397+ final controllerCompleter = Completer <ExampleGoogleMapController >();
1398+
1399+ final GoogleMapsInspectorPlatform inspector =
1400+ GoogleMapsInspectorPlatform .instance! ;
1401+
1402+ await tester.pumpWidget (
1403+ Directionality (
1404+ textDirection: TextDirection .ltr,
1405+ child: ExampleGoogleMap (
1406+ key: key,
1407+ initialCameraPosition: _kInitialCameraPosition,
1408+ clusterManagers: clusterManagers,
1409+ markerType: MarkerType .advancedMarker,
1410+ markers: Set <Marker >.of (markers.values),
1411+ onMapCreated: (ExampleGoogleMapController googleMapController) {
1412+ controllerCompleter.complete (googleMapController);
1413+ },
1414+ ),
1415+ ),
1416+ );
1417+
1418+ final ExampleGoogleMapController controller =
1419+ await controllerCompleter.future;
1420+
1421+ for (final cm in clusterManagers) {
1422+ final List <Cluster > clusters = await inspector.getClusters (
1423+ mapId: controller.mapId,
1424+ clusterManagerId: cm.clusterManagerId,
1425+ );
1426+ final int markersAmountForClusterManager = clusters
1427+ .map <int >((Cluster cluster) => cluster.count)
1428+ .reduce ((int value, int element) => value + element);
1429+ expect (markersAmountForClusterManager, markersPerClusterManager);
1430+ }
13711431
1432+ // Remove markers from clusterManagers and test that clusterManagers are empty.
1433+ for (final MapEntry <MarkerId , AdvancedMarker > entry in markers.entries) {
1434+ markers[entry.key] = _copyAdvancedMarkerWithClusterManagerId (
1435+ entry.value,
1436+ null ,
1437+ );
1438+ }
13721439 await tester.pumpWidget (
13731440 Directionality (
13741441 textDirection: TextDirection .ltr,
13751442 child: ExampleGoogleMap (
13761443 key: key,
13771444 initialCameraPosition: _kInitialCameraPosition,
1378- mapId: _kCloudMapId,
1445+ clusterManagers: clusterManagers,
1446+ markers: Set <Marker >.of (markers.values),
1447+ ),
1448+ ),
1449+ );
1450+
1451+ for (final cm in clusterManagers) {
1452+ final List <Cluster > clusters = await inspector.getClusters (
1453+ mapId: controller.mapId,
1454+ clusterManagerId: cm.clusterManagerId,
1455+ );
1456+ expect (clusters.length, 0 );
1457+ }
1458+ });
1459+
1460+ testWidgets ('testMapId' , (WidgetTester tester) async {
1461+ final Key key = GlobalKey ();
1462+
1463+ await tester.pumpWidget (
1464+ Directionality (
1465+ textDirection: TextDirection .ltr,
1466+ child: ExampleGoogleMap (
1467+ key: key,
1468+ initialCameraPosition: _kInitialCameraPosition,
1469+ mapId: _kMapId,
13791470 ),
13801471 ),
13811472 );
@@ -2069,6 +2160,38 @@ void main() {
20692160 // Hanging in CI, https://github.com/flutter/flutter/issues/166139
20702161 skip: true ,
20712162 );
2163+
2164+ testWidgets ('markerWithPinConfig' , (WidgetTester tester) async {
2165+ final markers = < AdvancedMarker > {
2166+ AdvancedMarker (
2167+ markerId: const MarkerId ('1' ),
2168+ icon: BitmapDescriptor .pinConfig (
2169+ backgroundColor: Colors .green,
2170+ borderColor: Colors .greenAccent,
2171+ glyph: const TextGlyph (text: 'A' , textColor: Colors .white),
2172+ ),
2173+ ),
2174+ };
2175+
2176+ final controllerCompleter = Completer <ExampleGoogleMapController >();
2177+
2178+ await tester.pumpWidget (
2179+ Directionality (
2180+ textDirection: ui.TextDirection .ltr,
2181+ child: ExampleGoogleMap (
2182+ initialCameraPosition: const CameraPosition (
2183+ target: LatLng (10.0 , 20.0 ),
2184+ ),
2185+ markers: markers,
2186+ markerType: MarkerType .advancedMarker,
2187+ onMapCreated: (ExampleGoogleMapController controller) =>
2188+ controllerCompleter.complete (controller),
2189+ ),
2190+ ),
2191+ );
2192+ await tester.pumpAndSettle ();
2193+ await controllerCompleter.future;
2194+ });
20722195}
20732196
20742197class _DebugTileProvider implements TileProvider {
@@ -2255,3 +2378,29 @@ Future<void> _checkCameraUpdateByType(
22552378 expect (currentPosition.zoom, wrapMatcher (equals (_kInitialZoomLevel - 1 )));
22562379 }
22572380}
2381+
2382+ AdvancedMarker _copyAdvancedMarkerWithClusterManagerId (
2383+ AdvancedMarker marker,
2384+ ClusterManagerId ? clusterManagerId,
2385+ ) {
2386+ return AdvancedMarker (
2387+ markerId: marker.markerId,
2388+ alpha: marker.alpha,
2389+ anchor: marker.anchor,
2390+ consumeTapEvents: marker.consumeTapEvents,
2391+ draggable: marker.draggable,
2392+ flat: marker.flat,
2393+ icon: marker.icon,
2394+ infoWindow: marker.infoWindow,
2395+ position: marker.position,
2396+ rotation: marker.rotation,
2397+ visible: marker.visible,
2398+ zIndex: marker.zIndex.toInt (),
2399+ onTap: marker.onTap,
2400+ onDragStart: marker.onDragStart,
2401+ onDrag: marker.onDrag,
2402+ onDragEnd: marker.onDragEnd,
2403+ clusterManagerId: clusterManagerId,
2404+ collisionBehavior: marker.collisionBehavior,
2405+ );
2406+ }
0 commit comments