[google_maps_flutter] Use an interface for test inspection (#6116)

diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md
index 84f7867..bf7a705 100644
--- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md
+++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md
@@ -1,5 +1,7 @@
-## NEXT
+## 2.1.9
 
+* Updates integration tests to use the new inspector interface.
+* Removes obsolete test-only method for accessing a map controller's method channel.
 * Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/106316).
 
 ## 2.1.8
diff --git a/packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_map_inspector.dart b/packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_map_inspector.dart
index fe3461b..95ca969 100644
--- a/packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_map_inspector.dart
+++ b/packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_map_inspector.dart
@@ -2,87 +2,125 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#106316)
-// ignore: unnecessary_import
-import 'dart:typed_data';
-import 'package:flutter/services.dart';
-import 'package:google_maps_flutter/google_maps_flutter.dart';
+import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
 
-/// Inspect Google Maps state using the platform SDK.
-///
-/// This class is primarily used for testing. The methods on this
-/// class should call "getters" on the GoogleMap object or equivalent
-/// on the platform side.
-class GoogleMapInspector {
-  GoogleMapInspector(this._channel);
+/// A method-channel-based implementation of [GoogleMapsInspectorPlatform], for
+/// use in tests in conjunction with [MethodChannelGoogleMapsFlutter].
+// TODO(stuartmorgan): Move this into the platform implementations when
+// federating the mobile implementations.
+class MethodChannelGoogleMapsInspector extends GoogleMapsInspectorPlatform {
+  /// Creates a method-channel-based inspector instance that gets the channel
+  /// for a given map ID from [mapsPlatform].
+  MethodChannelGoogleMapsInspector(MethodChannelGoogleMapsFlutter mapsPlatform)
+      : _mapsPlatform = mapsPlatform;
 
-  final MethodChannel _channel;
+  final MethodChannelGoogleMapsFlutter _mapsPlatform;
 
-  Future<bool?> isCompassEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isCompassEnabled');
+  @override
+  Future<bool> areBuildingsEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isBuildingsEnabled'))!;
   }
 
-  Future<bool?> isMapToolbarEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isMapToolbarEnabled');
+  @override
+  Future<bool> areRotateGesturesEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isRotateGesturesEnabled'))!;
   }
 
-  Future<MinMaxZoomPreference> getMinMaxZoomLevels() async {
-    final List<double> zoomLevels =
-        (await _channel.invokeMethod<List<dynamic>>('map#getMinMaxZoomLevels'))!
-            .cast<double>();
+  @override
+  Future<bool> areScrollGesturesEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isScrollGesturesEnabled'))!;
+  }
+
+  @override
+  Future<bool> areTiltGesturesEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isTiltGesturesEnabled'))!;
+  }
+
+  @override
+  Future<bool> areZoomControlsEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isZoomControlsEnabled'))!;
+  }
+
+  @override
+  Future<bool> areZoomGesturesEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isZoomGesturesEnabled'))!;
+  }
+
+  @override
+  Future<MinMaxZoomPreference> getMinMaxZoomLevels({required int mapId}) async {
+    final List<double> zoomLevels = (await _mapsPlatform
+            .channel(mapId)
+            .invokeMethod<List<dynamic>>('map#getMinMaxZoomLevels'))!
+        .cast<double>();
     return MinMaxZoomPreference(zoomLevels[0], zoomLevels[1]);
   }
 
-  Future<double?> getZoomLevel() async {
-    final double? zoomLevel =
-        await _channel.invokeMethod<double>('map#getZoomLevel');
-    return zoomLevel;
-  }
-
-  Future<bool?> isZoomGesturesEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isZoomGesturesEnabled');
-  }
-
-  Future<bool?> isZoomControlsEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isZoomControlsEnabled');
-  }
-
-  Future<bool?> isLiteModeEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isLiteModeEnabled');
-  }
-
-  Future<bool?> isRotateGesturesEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isRotateGesturesEnabled');
-  }
-
-  Future<bool?> isTiltGesturesEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isTiltGesturesEnabled');
-  }
-
-  Future<bool?> isScrollGesturesEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isScrollGesturesEnabled');
-  }
-
-  Future<bool?> isMyLocationButtonEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isMyLocationButtonEnabled');
-  }
-
-  Future<bool?> isTrafficEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isTrafficEnabled');
-  }
-
-  Future<bool?> isBuildingsEnabled() async {
-    return await _channel.invokeMethod<bool>('map#isBuildingsEnabled');
-  }
-
-  Future<Uint8List?> takeSnapshot() async {
-    return await _channel.invokeMethod<Uint8List>('map#takeSnapshot');
-  }
-
-  Future<Map<String, dynamic>?> getTileOverlayInfo(String id) async {
-    return await _channel.invokeMapMethod<String, dynamic>(
-        'map#getTileOverlayInfo', <String, String>{
-      'tileOverlayId': id,
+  @override
+  Future<TileOverlay?> getTileOverlayInfo(TileOverlayId tileOverlayId,
+      {required int mapId}) async {
+    final Map<String, Object?>? tileInfo = await _mapsPlatform
+        .channel(mapId)
+        .invokeMapMethod<String, dynamic>(
+            'map#getTileOverlayInfo', <String, String>{
+      'tileOverlayId': tileOverlayId.value,
     });
+    if (tileInfo == null) {
+      return null;
+    }
+    return TileOverlay(
+      tileOverlayId: tileOverlayId,
+      fadeIn: tileInfo['fadeIn']! as bool,
+      transparency: tileInfo['transparency']! as double,
+      visible: tileInfo['visible']! as bool,
+      // Android and iOS return different types.
+      zIndex: (tileInfo['zIndex']! as num).toInt(),
+    );
+  }
+
+  @override
+  Future<bool> isCompassEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isCompassEnabled'))!;
+  }
+
+  @override
+  Future<bool> isLiteModeEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isLiteModeEnabled'))!;
+  }
+
+  @override
+  Future<bool> isMapToolbarEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isMapToolbarEnabled'))!;
+  }
+
+  @override
+  Future<bool> isMyLocationButtonEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isMyLocationButtonEnabled'))!;
+  }
+
+  @override
+  Future<bool> isTrafficEnabled({required int mapId}) async {
+    return (await _mapsPlatform
+        .channel(mapId)
+        .invokeMethod<bool>('map#isTrafficEnabled'))!;
   }
 }
diff --git a/packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_maps_test.dart b/packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_maps_test.dart
index 8742ff3..d82a582 100644
--- a/packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_maps_test.dart
+++ b/packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_maps_test.dart
@@ -10,6 +10,7 @@
 import 'package:flutter/material.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';
 import 'package:integration_test/integration_test.dart';
 
 import 'google_map_inspector.dart';
@@ -22,10 +23,19 @@
 void main() {
   IntegrationTestWidgetsFlutterBinding.ensureInitialized();
 
+  // TODO(stuartmorgan): Remove this once mobile implementations are federated
+  // and registering their own inpector implementations, and just call
+  // enableDebugInspection.
+  if (GoogleMapsFlutterPlatform.instance is MethodChannelGoogleMapsFlutter) {
+    GoogleMapsInspectorPlatform.instance = MethodChannelGoogleMapsInspector(
+        GoogleMapsFlutterPlatform.instance as MethodChannelGoogleMapsFlutter);
+  } else {
+    GoogleMapsFlutterPlatform.instance.enableDebugInspection();
+  }
+
   testWidgets('testCompassToggle', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
       child: GoogleMap(
@@ -33,16 +43,15 @@
         initialCameraPosition: _kInitialCameraPosition,
         compassEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? compassEnabled = await inspector.isCompassEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool compassEnabled = await inspector.isCompassEnabled(mapId: mapId);
     expect(compassEnabled, false);
 
     await tester.pumpWidget(Directionality(
@@ -57,14 +66,13 @@
       ),
     ));
 
-    compassEnabled = await inspector.isCompassEnabled();
+    compassEnabled = await inspector.isCompassEnabled(mapId: mapId);
     expect(compassEnabled, true);
   });
 
   testWidgets('testMapToolbarToggle', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -73,16 +81,15 @@
         initialCameraPosition: _kInitialCameraPosition,
         mapToolbarEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? mapToolbarEnabled = await inspector.isMapToolbarEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool mapToolbarEnabled = await inspector.isMapToolbarEnabled(mapId: mapId);
     expect(mapToolbarEnabled, false);
 
     await tester.pumpWidget(Directionality(
@@ -97,7 +104,7 @@
       ),
     ));
 
-    mapToolbarEnabled = await inspector.isMapToolbarEnabled();
+    mapToolbarEnabled = await inspector.isMapToolbarEnabled(mapId: mapId);
     expect(mapToolbarEnabled, Platform.isAndroid);
   });
 
@@ -113,9 +120,8 @@
     //
     // Thus we test iOS and Android a little differently here.
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
-    late GoogleMapController controller;
+    final Completer<GoogleMapController> controllerCompleter =
+        Completer<GoogleMapController>();
 
     const MinMaxZoomPreference initialZoomLevel = MinMaxZoomPreference(4, 8);
     const MinMaxZoomPreference finalZoomLevel = MinMaxZoomPreference(6, 10);
@@ -127,30 +133,28 @@
         initialCameraPosition: _kInitialCameraPosition,
         minMaxZoomPreference: initialZoomLevel,
         onMapCreated: (GoogleMapController c) async {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(c.channel!);
-          controller = c;
-          inspectorCompleter.complete(inspector);
+          controllerCompleter.complete(c);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
+    final GoogleMapController controller = await controllerCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
 
     if (Platform.isIOS) {
       final MinMaxZoomPreference zoomLevel =
-          await inspector.getMinMaxZoomLevels();
+          await inspector.getMinMaxZoomLevels(mapId: controller.mapId);
       expect(zoomLevel, equals(initialZoomLevel));
     } else if (Platform.isAndroid) {
       await controller.moveCamera(CameraUpdate.zoomTo(15));
       await tester.pumpAndSettle();
-      double? zoomLevel = await inspector.getZoomLevel();
+      double? zoomLevel = await controller.getZoomLevel();
       expect(zoomLevel, equals(initialZoomLevel.maxZoom));
 
       await controller.moveCamera(CameraUpdate.zoomTo(1));
       await tester.pumpAndSettle();
-      zoomLevel = await inspector.getZoomLevel();
+      zoomLevel = await controller.getZoomLevel();
       expect(zoomLevel, equals(initialZoomLevel.minZoom));
     }
 
@@ -168,25 +172,24 @@
 
     if (Platform.isIOS) {
       final MinMaxZoomPreference zoomLevel =
-          await inspector.getMinMaxZoomLevels();
+          await inspector.getMinMaxZoomLevels(mapId: controller.mapId);
       expect(zoomLevel, equals(finalZoomLevel));
     } else {
       await controller.moveCamera(CameraUpdate.zoomTo(15));
       await tester.pumpAndSettle();
-      double? zoomLevel = await inspector.getZoomLevel();
+      double? zoomLevel = await controller.getZoomLevel();
       expect(zoomLevel, equals(finalZoomLevel.maxZoom));
 
       await controller.moveCamera(CameraUpdate.zoomTo(1));
       await tester.pumpAndSettle();
-      zoomLevel = await inspector.getZoomLevel();
+      zoomLevel = await controller.getZoomLevel();
       expect(zoomLevel, equals(finalZoomLevel.minZoom));
     }
   });
 
   testWidgets('testZoomGesturesEnabled', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -195,16 +198,16 @@
         initialCameraPosition: _kInitialCameraPosition,
         zoomGesturesEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? zoomGesturesEnabled = await inspector.isZoomGesturesEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool zoomGesturesEnabled =
+        await inspector.areZoomGesturesEnabled(mapId: mapId);
     expect(zoomGesturesEnabled, false);
 
     await tester.pumpWidget(Directionality(
@@ -219,14 +222,13 @@
       ),
     ));
 
-    zoomGesturesEnabled = await inspector.isZoomGesturesEnabled();
+    zoomGesturesEnabled = await inspector.areZoomGesturesEnabled(mapId: mapId);
     expect(zoomGesturesEnabled, true);
   });
 
   testWidgets('testZoomControlsEnabled', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -234,16 +236,16 @@
         key: key,
         initialCameraPosition: _kInitialCameraPosition,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? zoomControlsEnabled = await inspector.isZoomControlsEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool zoomControlsEnabled =
+        await inspector.areZoomControlsEnabled(mapId: mapId);
     expect(zoomControlsEnabled, !Platform.isIOS);
 
     /// Zoom Controls functionality is not available on iOS at the moment.
@@ -260,15 +262,15 @@
         ),
       ));
 
-      zoomControlsEnabled = await inspector.isZoomControlsEnabled();
+      zoomControlsEnabled =
+          await inspector.areZoomControlsEnabled(mapId: mapId);
       expect(zoomControlsEnabled, false);
     }
   });
 
   testWidgets('testLiteModeEnabled', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -277,16 +279,15 @@
         initialCameraPosition: _kInitialCameraPosition,
         liteModeEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? liteModeEnabled = await inspector.isLiteModeEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool liteModeEnabled = await inspector.isLiteModeEnabled(mapId: mapId);
     expect(liteModeEnabled, false);
 
     await tester.pumpWidget(Directionality(
@@ -301,14 +302,13 @@
       ),
     ));
 
-    liteModeEnabled = await inspector.isLiteModeEnabled();
+    liteModeEnabled = await inspector.isLiteModeEnabled(mapId: mapId);
     expect(liteModeEnabled, true);
   }, skip: !Platform.isAndroid);
 
   testWidgets('testRotateGesturesEnabled', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -317,16 +317,16 @@
         initialCameraPosition: _kInitialCameraPosition,
         rotateGesturesEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? rotateGesturesEnabled = await inspector.isRotateGesturesEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool rotateGesturesEnabled =
+        await inspector.areRotateGesturesEnabled(mapId: mapId);
     expect(rotateGesturesEnabled, false);
 
     await tester.pumpWidget(Directionality(
@@ -341,14 +341,14 @@
       ),
     ));
 
-    rotateGesturesEnabled = await inspector.isRotateGesturesEnabled();
+    rotateGesturesEnabled =
+        await inspector.areRotateGesturesEnabled(mapId: mapId);
     expect(rotateGesturesEnabled, true);
   });
 
   testWidgets('testTiltGesturesEnabled', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -357,16 +357,16 @@
         initialCameraPosition: _kInitialCameraPosition,
         tiltGesturesEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? tiltGesturesEnabled = await inspector.isTiltGesturesEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool tiltGesturesEnabled =
+        await inspector.areTiltGesturesEnabled(mapId: mapId);
     expect(tiltGesturesEnabled, false);
 
     await tester.pumpWidget(Directionality(
@@ -381,14 +381,13 @@
       ),
     ));
 
-    tiltGesturesEnabled = await inspector.isTiltGesturesEnabled();
+    tiltGesturesEnabled = await inspector.areTiltGesturesEnabled(mapId: mapId);
     expect(tiltGesturesEnabled, true);
   });
 
   testWidgets('testScrollGesturesEnabled', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -397,16 +396,16 @@
         initialCameraPosition: _kInitialCameraPosition,
         scrollGesturesEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? scrollGesturesEnabled = await inspector.isScrollGesturesEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool scrollGesturesEnabled =
+        await inspector.areScrollGesturesEnabled(mapId: mapId);
     expect(scrollGesturesEnabled, false);
 
     await tester.pumpWidget(Directionality(
@@ -421,7 +420,8 @@
       ),
     ));
 
-    scrollGesturesEnabled = await inspector.isScrollGesturesEnabled();
+    scrollGesturesEnabled =
+        await inspector.areScrollGesturesEnabled(mapId: mapId);
     expect(scrollGesturesEnabled, true);
   });
 
@@ -547,8 +547,7 @@
 
   testWidgets('testTraffic', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -557,16 +556,15 @@
         initialCameraPosition: _kInitialCameraPosition,
         trafficEnabled: true,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? isTrafficEnabled = await inspector.isTrafficEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool isTrafficEnabled = await inspector.isTrafficEnabled(mapId: mapId);
     expect(isTrafficEnabled, true);
 
     await tester.pumpWidget(Directionality(
@@ -581,14 +579,13 @@
       ),
     ));
 
-    isTrafficEnabled = await inspector.isTrafficEnabled();
+    isTrafficEnabled = await inspector.isTrafficEnabled(mapId: mapId);
     expect(isTrafficEnabled, false);
   });
 
   testWidgets('testBuildings', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -597,24 +594,23 @@
         initialCameraPosition: _kInitialCameraPosition,
         buildingsEnabled: true,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    final bool? isBuildingsEnabled = await inspector.isBuildingsEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    final bool isBuildingsEnabled =
+        await inspector.areBuildingsEnabled(mapId: mapId);
     expect(isBuildingsEnabled, true);
   });
 
   // Location button tests are skipped in Android because we don't have location permission to test.
   testWidgets('testMyLocationButtonToggle', (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -624,16 +620,16 @@
         myLocationButtonEnabled: true,
         myLocationEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    bool? myLocationButtonEnabled = await inspector.isMyLocationButtonEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    bool myLocationButtonEnabled =
+        await inspector.isMyLocationButtonEnabled(mapId: mapId);
     expect(myLocationButtonEnabled, true);
 
     await tester.pumpWidget(Directionality(
@@ -649,15 +645,15 @@
       ),
     ));
 
-    myLocationButtonEnabled = await inspector.isMyLocationButtonEnabled();
+    myLocationButtonEnabled =
+        await inspector.isMyLocationButtonEnabled(mapId: mapId);
     expect(myLocationButtonEnabled, false);
   }, skip: Platform.isAndroid);
 
   testWidgets('testMyLocationButton initial value false',
       (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -667,25 +663,23 @@
         myLocationButtonEnabled: false,
         myLocationEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    final bool? myLocationButtonEnabled =
-        await inspector.isMyLocationButtonEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    final bool myLocationButtonEnabled =
+        await inspector.isMyLocationButtonEnabled(mapId: mapId);
     expect(myLocationButtonEnabled, false);
   }, skip: Platform.isAndroid);
 
   testWidgets('testMyLocationButton initial value true',
       (WidgetTester tester) async {
     final Key key = GlobalKey();
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<int> mapIdCompleter = Completer<int>();
 
     await tester.pumpWidget(Directionality(
       textDirection: TextDirection.ltr,
@@ -695,17 +689,16 @@
         myLocationButtonEnabled: true,
         myLocationEnabled: false,
         onMapCreated: (GoogleMapController controller) {
-          final GoogleMapInspector inspector =
-              // ignore: invalid_use_of_visible_for_testing_member
-              GoogleMapInspector(controller.channel!);
-          inspectorCompleter.complete(inspector);
+          mapIdCompleter.complete(controller.mapId);
         },
       ),
     ));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    final bool? myLocationButtonEnabled =
-        await inspector.isMyLocationButtonEnabled();
+    final int mapId = await mapIdCompleter.future;
+    final GoogleMapsInspectorPlatform inspector =
+        GoogleMapsInspectorPlatform.instance!;
+    final bool myLocationButtonEnabled =
+        await inspector.isMyLocationButtonEnabled(mapId: mapId);
     expect(myLocationButtonEnabled, true);
   }, skip: Platform.isAndroid);
 
@@ -962,8 +955,8 @@
   });
 
   testWidgets('testTakeSnapshot', (WidgetTester tester) async {
-    final Completer<GoogleMapInspector> inspectorCompleter =
-        Completer<GoogleMapInspector>();
+    final Completer<GoogleMapController> controllerCompleter =
+        Completer<GoogleMapController>();
 
     await tester.pumpWidget(
       Directionality(
@@ -971,10 +964,7 @@
         child: GoogleMap(
           initialCameraPosition: _kInitialCameraPosition,
           onMapCreated: (GoogleMapController controller) {
-            final GoogleMapInspector inspector =
-                // ignore: invalid_use_of_visible_for_testing_member
-                GoogleMapInspector(controller.channel!);
-            inspectorCompleter.complete(inspector);
+            controllerCompleter.complete(controller);
           },
         ),
       ),
@@ -982,8 +972,8 @@
 
     await tester.pumpAndSettle(const Duration(seconds: 3));
 
-    final GoogleMapInspector inspector = await inspectorCompleter.future;
-    final Uint8List? bytes = await inspector.takeSnapshot();
+    final GoogleMapController controller = await controllerCompleter.future;
+    final Uint8List? bytes = await controller.takeSnapshot();
     expect(bytes?.isNotEmpty, true);
   },
       // TODO(cyanglaz): un-skip the test when we can test this on CI with API key enabled.
@@ -993,8 +983,7 @@
   testWidgets(
     'set tileOverlay correctly',
     (WidgetTester tester) async {
-      final Completer<GoogleMapInspector> inspectorCompleter =
-          Completer<GoogleMapInspector>();
+      final Completer<int> mapIdCompleter = Completer<int>();
       final TileOverlay tileOverlay1 = TileOverlay(
         tileOverlayId: const TileOverlayId('tile_overlay_1'),
         tileProvider: _DebugTileProvider(),
@@ -1019,42 +1008,40 @@
             initialCameraPosition: _kInitialCameraPosition,
             tileOverlays: <TileOverlay>{tileOverlay1, tileOverlay2},
             onMapCreated: (GoogleMapController controller) {
-              final GoogleMapInspector inspector =
-                  // ignore: invalid_use_of_visible_for_testing_member
-                  GoogleMapInspector(controller.channel!);
-              inspectorCompleter.complete(inspector);
+              mapIdCompleter.complete(controller.mapId);
             },
           ),
         ),
       );
       await tester.pumpAndSettle(const Duration(seconds: 3));
 
-      final GoogleMapInspector inspector = await inspectorCompleter.future;
+      final int mapId = await mapIdCompleter.future;
+      final GoogleMapsInspectorPlatform inspector =
+          GoogleMapsInspectorPlatform.instance!;
 
-      final Map<String, dynamic> tileOverlayInfo1 =
-          (await inspector.getTileOverlayInfo('tile_overlay_1'))!;
-      final Map<String, dynamic> tileOverlayInfo2 =
-          (await inspector.getTileOverlayInfo('tile_overlay_2'))!;
+      final TileOverlay tileOverlayInfo1 = (await inspector
+          .getTileOverlayInfo(tileOverlay1.mapsId, mapId: mapId))!;
+      final TileOverlay tileOverlayInfo2 = (await inspector
+          .getTileOverlayInfo(tileOverlay2.mapsId, mapId: mapId))!;
 
-      expect(tileOverlayInfo1['visible'], isTrue);
-      expect(tileOverlayInfo1['fadeIn'], isTrue);
-      expect(tileOverlayInfo1['transparency'],
-          moreOrLessEquals(0.2, epsilon: 0.001));
-      expect(tileOverlayInfo1['zIndex'], 2);
+      expect(tileOverlayInfo1.visible, isTrue);
+      expect(tileOverlayInfo1.fadeIn, isTrue);
+      expect(
+          tileOverlayInfo1.transparency, moreOrLessEquals(0.2, epsilon: 0.001));
+      expect(tileOverlayInfo1.zIndex, 2);
 
-      expect(tileOverlayInfo2['visible'], isFalse);
-      expect(tileOverlayInfo2['fadeIn'], isFalse);
-      expect(tileOverlayInfo2['transparency'],
-          moreOrLessEquals(0.3, epsilon: 0.001));
-      expect(tileOverlayInfo2['zIndex'], 1);
+      expect(tileOverlayInfo2.visible, isFalse);
+      expect(tileOverlayInfo2.fadeIn, isFalse);
+      expect(
+          tileOverlayInfo2.transparency, moreOrLessEquals(0.3, epsilon: 0.001));
+      expect(tileOverlayInfo2.zIndex, 1);
     },
   );
 
   testWidgets(
     'update tileOverlays correctly',
     (WidgetTester tester) async {
-      final Completer<GoogleMapInspector> inspectorCompleter =
-          Completer<GoogleMapInspector>();
+      final Completer<int> mapIdCompleter = Completer<int>();
       final Key key = GlobalKey();
       final TileOverlay tileOverlay1 = TileOverlay(
         tileOverlayId: const TileOverlayId('tile_overlay_1'),
@@ -1081,16 +1068,15 @@
             initialCameraPosition: _kInitialCameraPosition,
             tileOverlays: <TileOverlay>{tileOverlay1, tileOverlay2},
             onMapCreated: (GoogleMapController controller) {
-              final GoogleMapInspector inspector =
-                  // ignore: invalid_use_of_visible_for_testing_member
-                  GoogleMapInspector(controller.channel!);
-              inspectorCompleter.complete(inspector);
+              mapIdCompleter.complete(controller.mapId);
             },
           ),
         ),
       );
 
-      final GoogleMapInspector inspector = await inspectorCompleter.future;
+      final int mapId = await mapIdCompleter.future;
+      final GoogleMapsInspectorPlatform inspector =
+          GoogleMapsInspectorPlatform.instance!;
 
       final TileOverlay tileOverlay1New = TileOverlay(
         tileOverlayId: const TileOverlayId('tile_overlay_1'),
@@ -1117,16 +1103,16 @@
 
       await tester.pumpAndSettle(const Duration(seconds: 3));
 
-      final Map<String, dynamic> tileOverlayInfo1 =
-          (await inspector.getTileOverlayInfo('tile_overlay_1'))!;
-      final Map<String, dynamic>? tileOverlayInfo2 =
-          await inspector.getTileOverlayInfo('tile_overlay_2');
+      final TileOverlay tileOverlayInfo1 = (await inspector
+          .getTileOverlayInfo(tileOverlay1.mapsId, mapId: mapId))!;
+      final TileOverlay? tileOverlayInfo2 =
+          await inspector.getTileOverlayInfo(tileOverlay2.mapsId, mapId: mapId);
 
-      expect(tileOverlayInfo1['visible'], isFalse);
-      expect(tileOverlayInfo1['fadeIn'], isFalse);
-      expect(tileOverlayInfo1['transparency'],
-          moreOrLessEquals(0.3, epsilon: 0.001));
-      expect(tileOverlayInfo1['zIndex'], 1);
+      expect(tileOverlayInfo1.visible, isFalse);
+      expect(tileOverlayInfo1.fadeIn, isFalse);
+      expect(
+          tileOverlayInfo1.transparency, moreOrLessEquals(0.3, epsilon: 0.001));
+      expect(tileOverlayInfo1.zIndex, 1);
 
       expect(tileOverlayInfo2, isNull);
     },
@@ -1135,8 +1121,7 @@
   testWidgets(
     'remove tileOverlays correctly',
     (WidgetTester tester) async {
-      final Completer<GoogleMapInspector> inspectorCompleter =
-          Completer<GoogleMapInspector>();
+      final Completer<int> mapIdCompleter = Completer<int>();
       final Key key = GlobalKey();
       final TileOverlay tileOverlay1 = TileOverlay(
         tileOverlayId: const TileOverlayId('tile_overlay_1'),
@@ -1155,16 +1140,15 @@
             initialCameraPosition: _kInitialCameraPosition,
             tileOverlays: <TileOverlay>{tileOverlay1},
             onMapCreated: (GoogleMapController controller) {
-              final GoogleMapInspector inspector =
-                  // ignore: invalid_use_of_visible_for_testing_member
-                  GoogleMapInspector(controller.channel!);
-              inspectorCompleter.complete(inspector);
+              mapIdCompleter.complete(controller.mapId);
             },
           ),
         ),
       );
 
-      final GoogleMapInspector inspector = await inspectorCompleter.future;
+      final int mapId = await mapIdCompleter.future;
+      final GoogleMapsInspectorPlatform inspector =
+          GoogleMapsInspectorPlatform.instance!;
 
       await tester.pumpWidget(
         Directionality(
@@ -1180,8 +1164,8 @@
       );
 
       await tester.pumpAndSettle(const Duration(seconds: 3));
-      final Map<String, dynamic>? tileOverlayInfo1 =
-          await inspector.getTileOverlayInfo('tile_overlay_1');
+      final TileOverlay? tileOverlayInfo1 =
+          await inspector.getTileOverlayInfo(tileOverlay1.mapsId, mapId: mapId);
 
       expect(tileOverlayInfo1, isNull);
     },
diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart
index 4eeb857..751930a 100644
--- a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart
+++ b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart
@@ -13,7 +13,6 @@
 import 'package:flutter/foundation.dart';
 import 'package:flutter/gestures.dart';
 import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
 import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
 
 export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'
diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart
index 71b1434..cd3d078 100644
--- a/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart
+++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart
@@ -35,20 +35,6 @@
     );
   }
 
-  /// Used to communicate with the native platform.
-  ///
-  /// Accessible only for testing.
-  // TODO(dit): Remove this getter, https://github.com/flutter/flutter/issues/55504.
-  @visibleForTesting
-  MethodChannel? get channel {
-    if (GoogleMapsFlutterPlatform.instance is MethodChannelGoogleMapsFlutter) {
-      return (GoogleMapsFlutterPlatform.instance
-              as MethodChannelGoogleMapsFlutter)
-          .channel(mapId);
-    }
-    return null;
-  }
-
   final _GoogleMapState _googleMapState;
 
   void _connectStreams(int mapId) {
diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml
index 1a0dd4e..f546c8a 100644
--- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml
+++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml
@@ -2,7 +2,7 @@
 description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
 repository: https://github.com/flutter/plugins/tree/main/packages/google_maps_flutter/google_maps_flutter
 issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
-version: 2.1.8
+version: 2.1.9
 
 environment:
   sdk: ">=2.14.0 <3.0.0"
@@ -21,7 +21,7 @@
   flutter:
     sdk: flutter
   flutter_plugin_android_lifecycle: ^2.0.1
-  google_maps_flutter_platform_interface: ^2.2.0
+  google_maps_flutter_platform_interface: ^2.2.1
 
 dev_dependencies:
   flutter_test: