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

Commit 398f8f7

Browse files
[google_maps_flutter] Use an interface for test inspection (#6116)
1 parent c3ee723 commit 398f8f7

File tree

6 files changed

+270
-261
lines changed

6 files changed

+270
-261
lines changed

packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## NEXT
1+
## 2.1.9
22

3+
* Updates integration tests to use the new inspector interface.
4+
* Removes obsolete test-only method for accessing a map controller's method channel.
35
* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/106316).
46

57
## 2.1.8

packages/google_maps_flutter/google_maps_flutter/example/integration_test/google_map_inspector.dart

Lines changed: 96 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,125 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#106316)
6-
// ignore: unnecessary_import
7-
import 'dart:typed_data';
8-
import 'package:flutter/services.dart';
9-
import 'package:google_maps_flutter/google_maps_flutter.dart';
10-
11-
/// Inspect Google Maps state using the platform SDK.
12-
///
13-
/// This class is primarily used for testing. The methods on this
14-
/// class should call "getters" on the GoogleMap object or equivalent
15-
/// on the platform side.
16-
class GoogleMapInspector {
17-
GoogleMapInspector(this._channel);
18-
19-
final MethodChannel _channel;
20-
21-
Future<bool?> isCompassEnabled() async {
22-
return await _channel.invokeMethod<bool>('map#isCompassEnabled');
5+
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
6+
7+
/// A method-channel-based implementation of [GoogleMapsInspectorPlatform], for
8+
/// use in tests in conjunction with [MethodChannelGoogleMapsFlutter].
9+
// TODO(stuartmorgan): Move this into the platform implementations when
10+
// federating the mobile implementations.
11+
class MethodChannelGoogleMapsInspector extends GoogleMapsInspectorPlatform {
12+
/// Creates a method-channel-based inspector instance that gets the channel
13+
/// for a given map ID from [mapsPlatform].
14+
MethodChannelGoogleMapsInspector(MethodChannelGoogleMapsFlutter mapsPlatform)
15+
: _mapsPlatform = mapsPlatform;
16+
17+
final MethodChannelGoogleMapsFlutter _mapsPlatform;
18+
19+
@override
20+
Future<bool> areBuildingsEnabled({required int mapId}) async {
21+
return (await _mapsPlatform
22+
.channel(mapId)
23+
.invokeMethod<bool>('map#isBuildingsEnabled'))!;
2324
}
2425

25-
Future<bool?> isMapToolbarEnabled() async {
26-
return await _channel.invokeMethod<bool>('map#isMapToolbarEnabled');
26+
@override
27+
Future<bool> areRotateGesturesEnabled({required int mapId}) async {
28+
return (await _mapsPlatform
29+
.channel(mapId)
30+
.invokeMethod<bool>('map#isRotateGesturesEnabled'))!;
2731
}
2832

29-
Future<MinMaxZoomPreference> getMinMaxZoomLevels() async {
30-
final List<double> zoomLevels =
31-
(await _channel.invokeMethod<List<dynamic>>('map#getMinMaxZoomLevels'))!
32-
.cast<double>();
33-
return MinMaxZoomPreference(zoomLevels[0], zoomLevels[1]);
34-
}
35-
36-
Future<double?> getZoomLevel() async {
37-
final double? zoomLevel =
38-
await _channel.invokeMethod<double>('map#getZoomLevel');
39-
return zoomLevel;
40-
}
41-
42-
Future<bool?> isZoomGesturesEnabled() async {
43-
return await _channel.invokeMethod<bool>('map#isZoomGesturesEnabled');
33+
@override
34+
Future<bool> areScrollGesturesEnabled({required int mapId}) async {
35+
return (await _mapsPlatform
36+
.channel(mapId)
37+
.invokeMethod<bool>('map#isScrollGesturesEnabled'))!;
4438
}
4539

46-
Future<bool?> isZoomControlsEnabled() async {
47-
return await _channel.invokeMethod<bool>('map#isZoomControlsEnabled');
40+
@override
41+
Future<bool> areTiltGesturesEnabled({required int mapId}) async {
42+
return (await _mapsPlatform
43+
.channel(mapId)
44+
.invokeMethod<bool>('map#isTiltGesturesEnabled'))!;
4845
}
4946

50-
Future<bool?> isLiteModeEnabled() async {
51-
return await _channel.invokeMethod<bool>('map#isLiteModeEnabled');
47+
@override
48+
Future<bool> areZoomControlsEnabled({required int mapId}) async {
49+
return (await _mapsPlatform
50+
.channel(mapId)
51+
.invokeMethod<bool>('map#isZoomControlsEnabled'))!;
5252
}
5353

54-
Future<bool?> isRotateGesturesEnabled() async {
55-
return await _channel.invokeMethod<bool>('map#isRotateGesturesEnabled');
54+
@override
55+
Future<bool> areZoomGesturesEnabled({required int mapId}) async {
56+
return (await _mapsPlatform
57+
.channel(mapId)
58+
.invokeMethod<bool>('map#isZoomGesturesEnabled'))!;
5659
}
5760

58-
Future<bool?> isTiltGesturesEnabled() async {
59-
return await _channel.invokeMethod<bool>('map#isTiltGesturesEnabled');
61+
@override
62+
Future<MinMaxZoomPreference> getMinMaxZoomLevels({required int mapId}) async {
63+
final List<double> zoomLevels = (await _mapsPlatform
64+
.channel(mapId)
65+
.invokeMethod<List<dynamic>>('map#getMinMaxZoomLevels'))!
66+
.cast<double>();
67+
return MinMaxZoomPreference(zoomLevels[0], zoomLevels[1]);
6068
}
6169

62-
Future<bool?> isScrollGesturesEnabled() async {
63-
return await _channel.invokeMethod<bool>('map#isScrollGesturesEnabled');
70+
@override
71+
Future<TileOverlay?> getTileOverlayInfo(TileOverlayId tileOverlayId,
72+
{required int mapId}) async {
73+
final Map<String, Object?>? tileInfo = await _mapsPlatform
74+
.channel(mapId)
75+
.invokeMapMethod<String, dynamic>(
76+
'map#getTileOverlayInfo', <String, String>{
77+
'tileOverlayId': tileOverlayId.value,
78+
});
79+
if (tileInfo == null) {
80+
return null;
81+
}
82+
return TileOverlay(
83+
tileOverlayId: tileOverlayId,
84+
fadeIn: tileInfo['fadeIn']! as bool,
85+
transparency: tileInfo['transparency']! as double,
86+
visible: tileInfo['visible']! as bool,
87+
// Android and iOS return different types.
88+
zIndex: (tileInfo['zIndex']! as num).toInt(),
89+
);
6490
}
6591

66-
Future<bool?> isMyLocationButtonEnabled() async {
67-
return await _channel.invokeMethod<bool>('map#isMyLocationButtonEnabled');
92+
@override
93+
Future<bool> isCompassEnabled({required int mapId}) async {
94+
return (await _mapsPlatform
95+
.channel(mapId)
96+
.invokeMethod<bool>('map#isCompassEnabled'))!;
6897
}
6998

70-
Future<bool?> isTrafficEnabled() async {
71-
return await _channel.invokeMethod<bool>('map#isTrafficEnabled');
99+
@override
100+
Future<bool> isLiteModeEnabled({required int mapId}) async {
101+
return (await _mapsPlatform
102+
.channel(mapId)
103+
.invokeMethod<bool>('map#isLiteModeEnabled'))!;
72104
}
73105

74-
Future<bool?> isBuildingsEnabled() async {
75-
return await _channel.invokeMethod<bool>('map#isBuildingsEnabled');
106+
@override
107+
Future<bool> isMapToolbarEnabled({required int mapId}) async {
108+
return (await _mapsPlatform
109+
.channel(mapId)
110+
.invokeMethod<bool>('map#isMapToolbarEnabled'))!;
76111
}
77112

78-
Future<Uint8List?> takeSnapshot() async {
79-
return await _channel.invokeMethod<Uint8List>('map#takeSnapshot');
113+
@override
114+
Future<bool> isMyLocationButtonEnabled({required int mapId}) async {
115+
return (await _mapsPlatform
116+
.channel(mapId)
117+
.invokeMethod<bool>('map#isMyLocationButtonEnabled'))!;
80118
}
81119

82-
Future<Map<String, dynamic>?> getTileOverlayInfo(String id) async {
83-
return await _channel.invokeMapMethod<String, dynamic>(
84-
'map#getTileOverlayInfo', <String, String>{
85-
'tileOverlayId': id,
86-
});
120+
@override
121+
Future<bool> isTrafficEnabled({required int mapId}) async {
122+
return (await _mapsPlatform
123+
.channel(mapId)
124+
.invokeMethod<bool>('map#isTrafficEnabled'))!;
87125
}
88126
}

0 commit comments

Comments
 (0)