Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rewrite inspector implementation, and update tests
  • Loading branch information
stuartmorgan-g committed Jul 18, 2022
commit 26e5ce612a17fb12f7c5c71bcd8c831185217e20
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.
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