diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index a74d42727e78..8101abbe9ca2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -1100,4 +1100,10 @@ public Boolean isLiteModeEnabled() { } return data; } + + @NonNull + @Override + public Boolean hasRegisteredMapBitmap(@NonNull Long id) { + return imageRegistry.getBitmap(id) != null; + } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/ImageRegistry.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/ImageRegistry.java index 43f03fd0d774..1e7dd9b91514 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/ImageRegistry.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/ImageRegistry.java @@ -68,7 +68,6 @@ public void clearBitmapCache() { registry.clear(); } - /** * Retrieves a BitmapDescriptor from the registry using the provided ID. * diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java index bd616b0c32ae..b8acf57f022f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java @@ -7440,6 +7440,9 @@ public interface MapsInspectorApi { @NonNull List getClusters(@NonNull String clusterManagerId); + @NonNull + Boolean hasRegisteredMapBitmap(@NonNull Long id); + /** The codec used by MapsInspectorApi. */ static @NonNull MessageCodec getCodec() { return PigeonCodec.INSTANCE; @@ -7782,6 +7785,31 @@ static void setUp( channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.google_maps_flutter_android.MapsInspectorApi.hasRegisteredMapBitmap" + + messageChannelSuffix, + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + ArrayList args = (ArrayList) message; + Long idArg = (Long) args.get(0); + try { + Boolean output = api.hasRegisteredMapBitmap(idArg); + wrapped.add(0, output); + } catch (Throwable exception) { + wrapped = wrapError(exception); + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } } } /** diff --git a/packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/bitmap_registry_tests.dart b/packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/bitmap_registry_tests.dart index e282de2f28a3..658d3400e888 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/bitmap_registry_tests.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/bitmap_registry_tests.dart @@ -1,4 +1,8 @@ +import 'dart:async'; + +import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_example/example_google_map.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; void bitmapRegistryTests() { @@ -10,7 +14,15 @@ void bitmapRegistryTests() { imagePixelRatio: 1.0, ); + final int mapId = await _pumpMap(tester); await GoogleMapsFlutterPlatform.instance.registerBitmap(1, bitmap); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isTrue, + ); }); testWidgets('Remove bitmap from cache', (WidgetTester tester) async { @@ -19,8 +31,24 @@ void bitmapRegistryTests() { imagePixelRatio: 1.0, ); + final int mapId = await _pumpMap(tester); await GoogleMapsFlutterPlatform.instance.registerBitmap(1, bitmap); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isTrue, + ); + await GoogleMapsFlutterPlatform.instance.unregisterBitmap(1); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isFalse, + ); }); testWidgets('Clear bitmap cache', (WidgetTester tester) async { @@ -29,8 +57,44 @@ void bitmapRegistryTests() { imagePixelRatio: 1.0, ); + final int mapId = await _pumpMap(tester); await GoogleMapsFlutterPlatform.instance.clearBitmapCache(); await GoogleMapsFlutterPlatform.instance.registerBitmap(1, bitmap); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isTrue, + ); + await GoogleMapsFlutterPlatform.instance.clearBitmapCache(); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isFalse, + ); }); } + +// Pump a map and return the map ID. +Future _pumpMap(WidgetTester tester) async { + final Completer controllerCompleter = + Completer(); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: ExampleGoogleMap( + initialCameraPosition: const CameraPosition(target: LatLng(0, 0)), + onMapCreated: (ExampleGoogleMapController googleMapController) { + controllerCompleter.complete(googleMapController); + }, + ), + )); + + final ExampleGoogleMapController controller = + await controllerCompleter.future; + return controller.mapId; +} diff --git a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_map_inspector_android.dart b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_map_inspector_android.dart index 76b8a8ce75d0..4deceb24847f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_map_inspector_android.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_map_inspector_android.dart @@ -116,4 +116,12 @@ class GoogleMapsInspectorAndroid extends GoogleMapsInspectorPlatform { GoogleMapsFlutterAndroid.clusterFromPlatformCluster(cluster!)) .toList(); } + + @override + Future hasRegisteredMapBitmap({ + required int mapId, + required int bitmapId, + }) { + return _inspectorProvider(mapId)!.hasRegisteredMapBitmap(bitmapId); + } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart index f0ed0db9f84e..1546bdd158ee 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart @@ -3440,6 +3440,35 @@ class MapsInspectorApi { .cast(); } } + + Future hasRegisteredMapBitmap(int id) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.google_maps_flutter_android.MapsInspectorApi.hasRegisteredMapBitmap$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([id]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as bool?)!; + } + } } /// API for interacting with the image registry. diff --git a/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart b/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart index ce8945f2962c..4d1aa5e4393f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart @@ -781,6 +781,7 @@ abstract class MapsInspectorApi { PlatformTileLayer? getTileOverlayInfo(String tileOverlayId); PlatformZoomRange getZoomRange(); List getClusters(String clusterManagerId); + bool hasRegisteredMapBitmap(int id); } /// API for interacting with the image registry. diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/integration_test/bitmap_registry_test.dart b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/integration_test/bitmap_registry_test.dart index dd0f8aeb27be..b6fd8a1856b7 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/integration_test/bitmap_registry_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/integration_test/bitmap_registry_test.dart @@ -1,6 +1,10 @@ +import 'dart:async'; + +import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:integration_test/integration_test.dart'; +import 'package:maps_example_dart/example_google_map.dart'; void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); @@ -12,7 +16,15 @@ void main() { imagePixelRatio: 1.0, ); + final int mapId = await _pumpMap(tester); await GoogleMapsFlutterPlatform.instance.registerBitmap(1, bitmap); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isTrue, + ); }); testWidgets('Remove bitmap from cache', (WidgetTester tester) async { @@ -21,8 +33,24 @@ void main() { imagePixelRatio: 1.0, ); + final int mapId = await _pumpMap(tester); await GoogleMapsFlutterPlatform.instance.registerBitmap(1, bitmap); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isTrue, + ); + await GoogleMapsFlutterPlatform.instance.unregisterBitmap(1); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isFalse, + ); }); testWidgets('Clear bitmap cache', (WidgetTester tester) async { @@ -31,8 +59,44 @@ void main() { imagePixelRatio: 1.0, ); + final int mapId = await _pumpMap(tester); await GoogleMapsFlutterPlatform.instance.clearBitmapCache(); await GoogleMapsFlutterPlatform.instance.registerBitmap(1, bitmap); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isTrue, + ); + await GoogleMapsFlutterPlatform.instance.clearBitmapCache(); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isFalse, + ); }); } + +// Pump a map and return the map ID. +Future _pumpMap(WidgetTester tester) async { + final Completer controllerCompleter = + Completer(); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: ExampleGoogleMap( + initialCameraPosition: const CameraPosition(target: LatLng(0, 0)), + onMapCreated: (ExampleGoogleMapController googleMapController) { + controllerCompleter.complete(googleMapController); + }, + ), + )); + + final ExampleGoogleMapController controller = + await controllerCompleter.future; + return controller.mapId; +} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m index 49008d558849..8bad6dcee570 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m @@ -103,6 +103,7 @@ @interface FGMMapCallHandler () @interface FGMMapInspector : NSObject - (instancetype)initWithMapController:(nonnull FLTGoogleMapController *)controller messenger:(NSObject *)messenger + imageRegistry:(nonnull FGMImageRegistry *)imageRegistry pigeonSuffix:(NSString *)suffix; @end @@ -113,6 +114,8 @@ @interface FGMMapInspector () @property(nonatomic, weak) FLTGoogleMapController *controller; /// The messenger this instance was registered with by Pigeon. @property(nonatomic, copy) NSObject *messenger; +/// ImageRegistry for registering bitmaps. +@property(nonatomic, weak) FGMImageRegistry *imageRegistry; /// The suffix this instance was registered under with Pigeon. @property(nonatomic, copy) NSString *pigeonSuffix; @end @@ -232,6 +235,7 @@ - (instancetype)initWithMapView:(GMSMapView *_Nonnull)mapView SetUpFGMMapsApiWithSuffix(registrar.messenger, _callHandler, pigeonSuffix); _inspector = [[FGMMapInspector alloc] initWithMapController:self messenger:registrar.messenger + imageRegistry:imageRegistry pigeonSuffix:pigeonSuffix]; SetUpFGMMapsInspectorApiWithSuffix(registrar.messenger, _inspector, pigeonSuffix); } @@ -743,12 +747,14 @@ @implementation FGMMapInspector - (instancetype)initWithMapController:(nonnull FLTGoogleMapController *)controller messenger:(NSObject *)messenger + imageRegistry:(nonnull FGMImageRegistry *)imageRegistry pigeonSuffix:(NSString *)suffix { self = [super init]; if (self) { _controller = controller; _messenger = messenger; _pigeonSuffix = suffix; + _imageRegistry = imageRegistry; } return self; } @@ -831,4 +837,10 @@ - (nullable FGMPlatformZoomRange *)zoomRange: max:@(self.controller.mapView.maxZoom)]; } +- (nullable NSNumber *)hasRegisteredMapBitmapId:(NSInteger)id + error:(FlutterError *_Nullable __autoreleasing *_Nonnull) + error { + return [self.imageRegistry getBitmap:@(id)] ? @(YES) : @(NO); +} + @end diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/messages.g.h b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/messages.g.h index da317643f512..a8e88cd4102b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/messages.g.h +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/messages.g.h @@ -843,6 +843,9 @@ extern void SetUpFGMMapsPlatformViewApiWithSuffix(id bin - (nullable NSArray *) clustersWithIdentifier:(NSString *)clusterManagerId error:(FlutterError *_Nullable *_Nonnull)error; +/// @return `nil` only when `error != nil`. +- (nullable NSNumber *)hasRegisteredMapBitmapId:(NSInteger)id + error:(FlutterError *_Nullable *_Nonnull)error; @end extern void SetUpFGMMapsInspectorApi(id binaryMessenger, diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/messages.g.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/messages.g.m index 53347bbb340d..e2867d850c7b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/messages.g.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/messages.g.m @@ -3153,6 +3153,30 @@ void SetUpFGMMapsInspectorApiWithSuffix(id binaryMesseng [channel setMessageHandler:nil]; } } + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:[NSString stringWithFormat:@"%@%@", + @"dev.flutter.pigeon.google_maps_flutter_ios." + @"MapsInspectorApi.hasRegisteredMapBitmap", + messageChannelSuffix] + binaryMessenger:binaryMessenger + codec:FGMGetMessagesCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(hasRegisteredMapBitmapId:error:)], + @"FGMMapsInspectorApi api (%@) doesn't respond to " + @"@selector(hasRegisteredMapBitmapId:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSInteger arg_id = [GetNullableObjectAtIndex(args, 0) integerValue]; + FlutterError *error; + NSNumber *output = [api hasRegisteredMapBitmapId:arg_id error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } } void SetUpFGMImageRegistryApi(id binaryMessenger, NSObject *api) { diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/google_map_inspector_ios.dart b/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/google_map_inspector_ios.dart index 823e210ce73b..745b8b590385 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/google_map_inspector_ios.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/google_map_inspector_ios.dart @@ -141,4 +141,12 @@ class GoogleMapsInspectorIOS extends GoogleMapsInspectorPlatform { GoogleMapsFlutterIOS.clusterFromPlatformCluster(cluster)) .toList(); } + + @override + Future hasRegisteredMapBitmap({ + required int mapId, + required int bitmapId, + }) { + return _inspectorProvider(mapId)!.hasRegisteredMapBitmap(bitmapId); + } } diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/messages.g.dart b/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/messages.g.dart index 297d7e0df5ae..040b9b89d261 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/messages.g.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/messages.g.dart @@ -3215,6 +3215,35 @@ class MapsInspectorApi { .cast(); } } + + Future hasRegisteredMapBitmap(int id) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.google_maps_flutter_ios.MapsInspectorApi.hasRegisteredMapBitmap$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([id]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as bool?)!; + } + } } /// API for interacting with the image registry. diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/pigeons/messages.dart b/packages/google_maps_flutter/google_maps_flutter_ios/pigeons/messages.dart index d7eadc4cad64..266b131aea3c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/pigeons/messages.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/pigeons/messages.dart @@ -761,6 +761,7 @@ abstract class MapsInspectorApi { PlatformZoomRange getZoomRange(); @ObjCSelector('clustersWithIdentifier:') List getClusters(String clusterManagerId); + bool hasRegisteredMapBitmap(int id); } /// API for interacting with the image registry. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_inspector_platform.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_inspector_platform.dart index 8bf6f6f89baf..a38baace66d1 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_inspector_platform.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_inspector_platform.dart @@ -137,4 +137,15 @@ abstract class GoogleMapsInspectorPlatform extends PlatformInterface { {required int mapId, required ClusterManagerId clusterManagerId}) { throw UnimplementedError('getClusters() has not been implemented.'); } + + /// Returns true if the bitmap with the given [id] is registered in the + /// bitmap registry. + Future hasRegisteredMapBitmap({ + required int mapId, + required int bitmapId, + }) { + throw UnimplementedError( + 'hasRegisteredMapBitmap() has not been implemented.', + ); + } } diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/bitmap_registry_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/bitmap_registry_test.dart index f5848be1a6ac..30d2ce39a128 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/bitmap_registry_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/bitmap_registry_test.dart @@ -1,3 +1,6 @@ +import 'dart:async'; + +import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; @@ -13,7 +16,15 @@ void main() { imagePixelRatio: 1.0, ); - await GoogleMapBitmapRegistry.instance.register(bitmap); + final int mapId = await _pumpMap(tester); + await GoogleMapsFlutterPlatform.instance.registerBitmap(1, bitmap); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isTrue, + ); }); testWidgets('Remove bitmap from cache', (WidgetTester tester) async { @@ -22,8 +33,24 @@ void main() { imagePixelRatio: 1.0, ); - final int id = await GoogleMapBitmapRegistry.instance.register(bitmap); - await GoogleMapBitmapRegistry.instance.unregister(id); + final int mapId = await _pumpMap(tester); + await GoogleMapsFlutterPlatform.instance.registerBitmap(1, bitmap); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isTrue, + ); + + await GoogleMapsFlutterPlatform.instance.unregisterBitmap(1); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isFalse, + ); }); testWidgets('Clear bitmap cache', (WidgetTester tester) async { @@ -32,8 +59,43 @@ void main() { imagePixelRatio: 1.0, ); - await GoogleMapBitmapRegistry.instance.clear(); - await GoogleMapBitmapRegistry.instance.register(bitmap); - await GoogleMapBitmapRegistry.instance.clear(); + final int mapId = await _pumpMap(tester); + await GoogleMapsFlutterPlatform.instance.clearBitmapCache(); + await GoogleMapsFlutterPlatform.instance.registerBitmap(1, bitmap); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isTrue, + ); + + await GoogleMapsFlutterPlatform.instance.clearBitmapCache(); + expect( + await GoogleMapsInspectorPlatform.instance!.hasRegisteredMapBitmap( + mapId: mapId, + bitmapId: 1, + ), + isFalse, + ); }); } + +// Pump a map and return the map ID. +Future _pumpMap(WidgetTester tester) async { + final Completer controllerCompleter = + Completer(); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: const CameraPosition(target: LatLng(0, 0)), + onMapCreated: (GoogleMapController googleMapController) { + controllerCompleter.complete(googleMapController); + }, + ), + )); + + final GoogleMapController controller = await controllerCompleter.future; + return controller.mapId; +} diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_inspector_web.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_inspector_web.dart index 98b474309584..2b8d77f2b172 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_inspector_web.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_inspector_web.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'image_registry.dart'; import 'marker_clustering.dart'; /// Function that gets the [MapConfiguration] for a given `mapId`. @@ -103,4 +104,12 @@ class GoogleMapsInspectorWeb extends GoogleMapsInspectorPlatform { ?.getClusters(clusterManagerId) ?? []; } + + @override + Future hasRegisteredMapBitmap({ + required int mapId, + required int bitmapId, + }) async { + return ImageRegistry.instance.getBitmap(bitmapId) != null; + } } diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/image_registry.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/image_registry.dart index 17d5a1169007..f9a15476bf46 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/image_registry.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/image_registry.dart @@ -3,7 +3,7 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf import '../google_maps_flutter_web.dart'; -/// Manages mapping between registered bitmap Ids and [gmaps.Icon] objects. +/// Manages mapping between registered bitmap IDs and [gmaps.Icon] objects. class ImageRegistry { /// Default constructor. ImageRegistry._();