@@ -239,6 +239,18 @@ void main() {
239
239
verify (api.clearTileCache (tileOverlayId));
240
240
});
241
241
242
+ test ('isAdvancedMarkersAvailable calls through' , () async {
243
+ const int mapId = 1 ;
244
+ final (GoogleMapsFlutterAndroid maps, MockMapsApi api) =
245
+ setUpMockMap (mapId: mapId);
246
+ when (api.isAdvancedMarkersAvailable ()).thenAnswer ((_) async => true );
247
+
248
+ await maps.isAdvancedMarkersAvailable (mapId: mapId);
249
+ final bool isAdvancedMarkersAvailable =
250
+ await api.isAdvancedMarkersAvailable ();
251
+ expect (isAdvancedMarkersAvailable, isTrue);
252
+ });
253
+
242
254
test ('updateMapConfiguration passes expected arguments' , () async {
243
255
const int mapId = 1 ;
244
256
final (GoogleMapsFlutterAndroid maps, MockMapsApi api) =
@@ -478,6 +490,94 @@ void main() {
478
490
}
479
491
});
480
492
493
+ test ('updateMarkers passes expected arguments (AdvancedMarkers)' , () async {
494
+ const int mapId = 1 ;
495
+ final (GoogleMapsFlutterAndroid maps, MockMapsApi api) =
496
+ setUpMockMap (mapId: mapId);
497
+
498
+ const AdvancedMarker object1 = AdvancedMarker (markerId: MarkerId ('1' ));
499
+ const AdvancedMarker object2old = AdvancedMarker (markerId: MarkerId ('2' ));
500
+ final AdvancedMarker object2new = object2old.copyWith (rotationParam: 42 );
501
+ const AdvancedMarker object3 = AdvancedMarker (markerId: MarkerId ('3' ));
502
+ await maps.updateMarkers (
503
+ MarkerUpdates .from (
504
+ < AdvancedMarker > {object1, object2old},
505
+ < AdvancedMarker > {object2new, object3},
506
+ ),
507
+ mapId: mapId);
508
+
509
+ final VerificationResult verification =
510
+ verify (api.updateMarkers (captureAny, captureAny, captureAny));
511
+ final List <PlatformMarker ?> toAdd =
512
+ verification.captured[0 ] as List <PlatformMarker ?>;
513
+ final List <PlatformMarker ?> toChange =
514
+ verification.captured[1 ] as List <PlatformMarker ?>;
515
+ final List <String ?> toRemove = verification.captured[2 ] as List <String ?>;
516
+ // Object one should be removed.
517
+ expect (toRemove.length, 1 );
518
+ expect (toRemove.first, object1.markerId.value);
519
+ // Object two should be changed.
520
+ {
521
+ expect (toChange.length, 1 );
522
+ final List <Object ?>? encoded = toChange.first? .encode () as List <Object ?>? ;
523
+ expect (encoded? [0 ], object2new.alpha);
524
+ final PlatformOffset ? offset = encoded? [1 ] as PlatformOffset ? ;
525
+ expect (offset? .dx, object2new.anchor.dx);
526
+ expect (offset? .dy, object2new.anchor.dy);
527
+ expect (encoded? .getRange (2 , 6 ).toList (), < Object ? > [
528
+ object2new.consumeTapEvents,
529
+ object2new.draggable,
530
+ object2new.flat,
531
+ object2new.icon.toJson (),
532
+ ]);
533
+ final PlatformInfoWindow ? window = encoded? [6 ] as PlatformInfoWindow ? ;
534
+ expect (window? .title, object2new.infoWindow.title);
535
+ expect (window? .snippet, object2new.infoWindow.snippet);
536
+ expect (window? .anchor.dx, object2new.infoWindow.anchor.dx);
537
+ expect (window? .anchor.dy, object2new.infoWindow.anchor.dy);
538
+ final PlatformLatLng ? latLng = encoded? [7 ] as PlatformLatLng ? ;
539
+ expect (latLng? .latitude, object2new.position.latitude);
540
+ expect (latLng? .longitude, object2new.position.longitude);
541
+ expect (encoded? .getRange (8 , 13 ), < Object ? > [
542
+ object2new.rotation,
543
+ object2new.visible,
544
+ object2new.zIndex,
545
+ object2new.markerId.value,
546
+ object2new.clusterManagerId? .value,
547
+ ]);
548
+ }
549
+ // Object 3 should be added.
550
+ {
551
+ expect (toAdd.length, 1 );
552
+ final List <Object ?>? encoded = toAdd.first? .encode () as List <Object ?>? ;
553
+ expect (encoded? [0 ], object3.alpha);
554
+ final PlatformOffset ? offset = encoded? [1 ] as PlatformOffset ? ;
555
+ expect (offset? .dx, object3.anchor.dx);
556
+ expect (offset? .dy, object3.anchor.dy);
557
+ expect (encoded? .getRange (2 , 6 ).toList (), < Object ? > [
558
+ object3.consumeTapEvents,
559
+ object3.draggable,
560
+ object3.flat,
561
+ object3.icon.toJson (),
562
+ ]);
563
+ final PlatformInfoWindow ? window = encoded? [6 ] as PlatformInfoWindow ? ;
564
+ expect (window? .title, object3.infoWindow.title);
565
+ expect (window? .snippet, object3.infoWindow.snippet);
566
+ expect (window? .anchor.dx, object3.infoWindow.anchor.dx);
567
+ expect (window? .anchor.dy, object3.infoWindow.anchor.dy);
568
+ final PlatformLatLng ? latLng = encoded? [7 ] as PlatformLatLng ? ;
569
+ expect (latLng? .latitude, object3.position.latitude);
570
+ expect (latLng? .longitude, object3.position.longitude);
571
+ expect (encoded? .getRange (8 , 13 ), < Object ? > [
572
+ object3.rotation,
573
+ object3.visible,
574
+ object3.zIndex,
575
+ object3.markerId.value,
576
+ object3.clusterManagerId? .value,
577
+ ]);
578
+ }
579
+ });
580
+
481
581
test ('updatePolygons passes expected arguments' , () async {
482
582
const int mapId = 1 ;
483
583
final (GoogleMapsFlutterAndroid maps, MockMapsApi api) =
@@ -1276,12 +1376,101 @@ void main() {
1276
1376
textDirection: TextDirection .ltr,
1277
1377
markerType: MarkerType .legacy,
1278
1378
),
1279
- mapConfiguration: const MapConfiguration (mapId: cloudMapId)));
1379
+ // Here deprecated cloudMapId is used to test that creation params have
1380
+ // the correct mapId
1381
+ mapConfiguration: const MapConfiguration (cloudMapId: cloudMapId)));
1280
1382
1281
1383
expect (
1282
1384
await passedCloudMapIdCompleter.future,
1283
1385
cloudMapId,
1284
1386
reason: 'Should pass cloudMapId on PlatformView creation message' ,
1285
1387
);
1286
1388
});
1389
+
1390
+ testWidgets ('mapId is passed' , (WidgetTester tester) async {
1391
+ const String mapId = '000000000000000' ; // Dummy map ID.
1392
+ final Completer <String > passedMapIdCompleter = Completer <String >();
1393
+
1394
+ TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger
1395
+ .setMockMethodCallHandler (
1396
+ SystemChannels .platform_views,
1397
+ (MethodCall methodCall) async {
1398
+ if (methodCall.method == 'create' ) {
1399
+ final Map <String , dynamic > args = Map <String , dynamic >.from (
1400
+ methodCall.arguments as Map <dynamic , dynamic >);
1401
+ if (args.containsKey ('params' )) {
1402
+ final Uint8List paramsUint8List = args['params' ] as Uint8List ;
1403
+ final ByteData byteData = ByteData .sublistView (paramsUint8List);
1404
+ final PlatformMapViewCreationParams ? creationParams =
1405
+ MapsApi .pigeonChannelCodec.decodeMessage (byteData)
1406
+ as PlatformMapViewCreationParams ? ;
1407
+ if (creationParams != null ) {
1408
+ final String ? passedMapId = creationParams.mapConfiguration.mapId;
1409
+ if (passedMapId != null ) {
1410
+ passedMapIdCompleter.complete (passedMapId);
1411
+ }
1412
+ }
1413
+ }
1414
+ }
1415
+ return 0 ;
1416
+ },
1417
+ );
1418
+
1419
+ final GoogleMapsFlutterAndroid maps = GoogleMapsFlutterAndroid ();
1420
+
1421
+ await tester.pumpWidget (maps.buildViewWithConfiguration (1 , (int id) {},
1422
+ widgetConfiguration: const MapWidgetConfiguration (
1423
+ initialCameraPosition: CameraPosition (target: LatLng (0 , 0 ), zoom: 1 ),
1424
+ textDirection: TextDirection .ltr,
1425
+ markerType: MarkerType .legacy,
1426
+ ),
1427
+ mapConfiguration: const MapConfiguration (mapId: mapId)));
1428
+
1429
+ expect (
1430
+ await passedMapIdCompleter.future,
1431
+ mapId,
1432
+ reason: 'Should pass mapId on PlatformView creation message' ,
1433
+ );
1434
+ });
1435
+
1436
+ test (
1437
+ 'Correct marker type is padded to platform view' ,
1438
+ () async {
1439
+ final GoogleMapsFlutterAndroid maps = GoogleMapsFlutterAndroid ();
1440
+ final Widget widget = maps.buildViewWithConfiguration (
1441
+ 1 ,
1442
+ (int _) {},
1443
+ widgetConfiguration: const MapWidgetConfiguration (
1444
+ initialCameraPosition: CameraPosition (target: LatLng (0 , 0 ), zoom: 1 ),
1445
+ textDirection: TextDirection .ltr,
1446
+ markerType: MarkerType .advanced,
1447
+ ),
1448
+ );
1449
+
1450
+ expect (widget, isA <AndroidView >());
1451
+ final dynamic creationParams = (widget as AndroidView ).creationParams;
1452
+ expect (creationParams, isA <PlatformMapViewCreationParams >());
1453
+ expect (
1454
+ (creationParams as PlatformMapViewCreationParams ).markerType,
1455
+ PlatformMarkerType .advanced,
1456
+ );
1457
+
1458
+ final Widget widget2 = maps.buildViewWithConfiguration (
1459
+ 1 ,
1460
+ (int _) {},
1461
+ widgetConfiguration: const MapWidgetConfiguration (
1462
+ initialCameraPosition: CameraPosition (target: LatLng (0 , 0 ), zoom: 1 ),
1463
+ textDirection: TextDirection .ltr,
1464
+ markerType: MarkerType .legacy,
1465
+ ),
1466
+ );
1467
+ expect (widget2, isA <AndroidView >());
1468
+ expect (
1469
+ ((widget2 as AndroidView ).creationParams
1470
+ as PlatformMapViewCreationParams )
1471
+ .markerType,
1472
+ PlatformMarkerType .legacy,
1473
+ );
1474
+ },
1475
+ );
1287
1476
}
0 commit comments