|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
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'))!; |
23 | 24 | } |
24 | 25 |
|
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'))!; |
27 | 31 | } |
28 | 32 |
|
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'))!; |
44 | 38 | } |
45 | 39 |
|
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'))!; |
48 | 45 | } |
49 | 46 |
|
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'))!; |
52 | 52 | } |
53 | 53 |
|
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'))!; |
56 | 59 | } |
57 | 60 |
|
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]); |
60 | 68 | } |
61 | 69 |
|
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 | + ); |
64 | 90 | } |
65 | 91 |
|
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'))!; |
68 | 97 | } |
69 | 98 |
|
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'))!; |
72 | 104 | } |
73 | 105 |
|
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'))!; |
76 | 111 | } |
77 | 112 |
|
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'))!; |
80 | 118 | } |
81 | 119 |
|
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'))!; |
87 | 125 | } |
88 | 126 | } |
0 commit comments