Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter] Use an interface for test inspection #6116

Merged
merged 8 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/// 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);

final MethodChannel _channel;

Future<bool?> isCompassEnabled() async {
return await _channel.invokeMethod<bool>('map#isCompassEnabled');
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';

/// 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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is here with a TODO instead of being moved to live with the default method channel implementation in the platform interface package because I plan to federate the mobile implementations shortly, and move them to in-package method channel implementations, at which point the default method channel inspector would be unused, but we'd be stuck with the extra copy indefinitely since removing it again would be a breaking change. Leaving it local for now lets us avoid that extra copy.

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 MethodChannelGoogleMapsFlutter _mapsPlatform;

@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>();
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');
@override
Future<bool> areScrollGesturesEnabled({required int mapId}) async {
return (await _mapsPlatform
.channel(mapId)
.invokeMethod<bool>('map#isScrollGesturesEnabled'))!;
}

Future<bool?> isZoomControlsEnabled() async {
return await _channel.invokeMethod<bool>('map#isZoomControlsEnabled');
@override
Future<bool> areTiltGesturesEnabled({required int mapId}) async {
return (await _mapsPlatform
.channel(mapId)
.invokeMethod<bool>('map#isTiltGesturesEnabled'))!;
}

Future<bool?> isLiteModeEnabled() async {
return await _channel.invokeMethod<bool>('map#isLiteModeEnabled');
@override
Future<bool> areZoomControlsEnabled({required int mapId}) async {
return (await _mapsPlatform
.channel(mapId)
.invokeMethod<bool>('map#isZoomControlsEnabled'))!;
}

Future<bool?> isRotateGesturesEnabled() async {
return await _channel.invokeMethod<bool>('map#isRotateGesturesEnabled');
@override
Future<bool> areZoomGesturesEnabled({required int mapId}) async {
return (await _mapsPlatform
.channel(mapId)
.invokeMethod<bool>('map#isZoomGesturesEnabled'))!;
}

Future<bool?> isTiltGesturesEnabled() async {
return await _channel.invokeMethod<bool>('map#isTiltGesturesEnabled');
@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<bool?> isScrollGesturesEnabled() async {
return await _channel.invokeMethod<bool>('map#isScrollGesturesEnabled');
@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(),
);
}

Future<bool?> isMyLocationButtonEnabled() async {
return await _channel.invokeMethod<bool>('map#isMyLocationButtonEnabled');
@override
Future<bool> isCompassEnabled({required int mapId}) async {
return (await _mapsPlatform
.channel(mapId)
.invokeMethod<bool>('map#isCompassEnabled'))!;
}

Future<bool?> isTrafficEnabled() async {
return await _channel.invokeMethod<bool>('map#isTrafficEnabled');
@override
Future<bool> isLiteModeEnabled({required int mapId}) async {
return (await _mapsPlatform
.channel(mapId)
.invokeMethod<bool>('map#isLiteModeEnabled'))!;
}

Future<bool?> isBuildingsEnabled() async {
return await _channel.invokeMethod<bool>('map#isBuildingsEnabled');
@override
Future<bool> isMapToolbarEnabled({required int mapId}) async {
return (await _mapsPlatform
.channel(mapId)
.invokeMethod<bool>('map#isMapToolbarEnabled'))!;
}

Future<Uint8List?> takeSnapshot() async {
return await _channel.invokeMethod<Uint8List>('map#takeSnapshot');
@override
Future<bool> isMyLocationButtonEnabled({required int mapId}) async {
return (await _mapsPlatform
.channel(mapId)
.invokeMethod<bool>('map#isMyLocationButtonEnabled'))!;
}

Future<Map<String, dynamic>?> getTileOverlayInfo(String id) async {
return await _channel.invokeMapMethod<String, dynamic>(
'map#getTileOverlayInfo', <String, String>{
'tileOverlayId': id,
});
@override
Future<bool> isTrafficEnabled({required int mapId}) async {
return (await _mapsPlatform
.channel(mapId)
.invokeMethod<bool>('map#isTrafficEnabled'))!;
}
}
Loading