Skip to content

Commit 9602350

Browse files
stuartmorgan-gmauricioluz
authored andcommitted
[google_maps_flutter] Updates platform interface to new analysis options (flutter#5793)
1 parent 32a2d60 commit 9602350

40 files changed

+505
-430
lines changed

analysis_options.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# with minimal changes for this repository. The goal is to move toward using a
33
# shared set of analysis options as much as possible, and eventually a shared
44
# file.
5-
#
6-
# Plugins that have not yet switched from the previous set of options have a
7-
# local analysis_options.yaml that points to analysis_options_legacy.yaml
8-
# instead.
95

106
# Specify analysis options.
117
#

analysis_options_legacy.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.1.7
22

3+
* Updates code for stricter analysis options.
34
* Removes unnecessary imports.
45

56
## 2.1.6

packages/google_maps_flutter/google_maps_flutter_platform_interface/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/google_maps_flutter_platform_interface.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
export 'src/events/map_event.dart';
56
export 'src/method_channel/method_channel_google_maps_flutter.dart'
67
show MethodChannelGoogleMapsFlutter;
78
export 'src/platform_interface/google_maps_flutter_platform.dart';
89
export 'src/types/types.dart';
9-
export 'src/events/map_event.dart';

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,29 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
3434
/// events to access the `.position` property, rather than the more generic `.value`
3535
/// yielded from the latter.
3636
class MapEvent<T> {
37-
/// The ID of the Map this event is associated to.
38-
final int mapId;
39-
40-
/// The value wrapped by this event
41-
final T value;
42-
4337
/// Build a Map Event, that relates a mapId with a given value.
4438
///
4539
/// The `mapId` is the id of the map that triggered the event.
4640
/// `value` may be `null` in events that don't transport any meaningful data.
4741
MapEvent(this.mapId, this.value);
42+
43+
/// The ID of the Map this event is associated to.
44+
final int mapId;
45+
46+
/// The value wrapped by this event
47+
final T value;
4848
}
4949

5050
/// A `MapEvent` associated to a `position`.
5151
class _PositionedMapEvent<T> extends MapEvent<T> {
52-
/// The position where this event happened.
53-
final LatLng position;
54-
5552
/// Build a Positioned MapEvent, that relates a mapId and a position with a value.
5653
///
5754
/// The `mapId` is the id of the map that triggered the event.
5855
/// `value` may be `null` in events that don't transport any meaningful data.
5956
_PositionedMapEvent(int mapId, this.position, T value) : super(mapId, value);
57+
58+
/// The position where this event happened.
59+
final LatLng position;
6060
}
6161

6262
// The following events are the ones exposed to the end user. They are semantic extensions

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ class UnknownMapIDError extends Error {
2727
/// Message describing the assertion error.
2828
final Object? message;
2929

30+
@override
3031
String toString() {
3132
if (message != null) {
32-
return "Unknown map ID $mapId: ${Error.safeToString(message)}";
33+
return 'Unknown map ID $mapId: ${Error.safeToString(message)}';
3334
}
34-
return "Unknown map ID $mapId";
35+
return 'Unknown map ID $mapId';
3536
}
3637
}
3738

@@ -48,19 +49,20 @@ class UnknownMapIDError extends Error {
4849
class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
4950
// Keep a collection of id -> channel
5051
// Every method call passes the int mapId
51-
final Map<int, MethodChannel> _channels = {};
52+
final Map<int, MethodChannel> _channels = <int, MethodChannel>{};
5253

5354
/// Accesses the MethodChannel associated to the passed mapId.
5455
MethodChannel channel(int mapId) {
55-
MethodChannel? channel = _channels[mapId];
56+
final MethodChannel? channel = _channels[mapId];
5657
if (channel == null) {
5758
throw UnknownMapIDError(mapId);
5859
}
5960
return channel;
6061
}
6162

6263
// Keep a collection of mapId to a map of TileOverlays.
63-
final Map<int, Map<TileOverlayId, TileOverlay>> _tileOverlays = {};
64+
final Map<int, Map<TileOverlayId, TileOverlay>> _tileOverlays =
65+
<int, Map<TileOverlayId, TileOverlay>>{};
6466

6567
/// Returns the channel for [mapId], creating it if it doesn't already exist.
6668
@visibleForTesting
@@ -77,7 +79,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
7779

7880
@override
7981
Future<void> init(int mapId) {
80-
MethodChannel channel = ensureChannelInitialized(mapId);
82+
final MethodChannel channel = ensureChannelInitialized(mapId);
8183
return channel.invokeMethod<void>('map#waitForMap');
8284
}
8385

@@ -91,12 +93,13 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
9193
//
9294
// It is a `broadcast` because multiple controllers will connect to
9395
// different stream views of this Controller.
94-
final StreamController<MapEvent> _mapEventStreamController =
95-
StreamController<MapEvent>.broadcast();
96+
final StreamController<MapEvent<Object?>> _mapEventStreamController =
97+
StreamController<MapEvent<Object?>>.broadcast();
9698

9799
// Returns a filtered view of the events in the _controller, by mapId.
98-
Stream<MapEvent> _events(int mapId) =>
99-
_mapEventStreamController.stream.where((event) => event.mapId == mapId);
100+
Stream<MapEvent<Object?>> _events(int mapId) =>
101+
_mapEventStreamController.stream
102+
.where((MapEvent<Object?> event) => event.mapId == mapId);
100103

101104
@override
102105
Stream<CameraMoveStartedEvent> onCameraMoveStarted({required int mapId}) {
@@ -185,52 +188,52 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
185188
case 'marker#onTap':
186189
_mapEventStreamController.add(MarkerTapEvent(
187190
mapId,
188-
MarkerId(call.arguments['markerId']),
191+
MarkerId(call.arguments['markerId'] as String),
189192
));
190193
break;
191194
case 'marker#onDragStart':
192195
_mapEventStreamController.add(MarkerDragStartEvent(
193196
mapId,
194197
LatLng.fromJson(call.arguments['position'])!,
195-
MarkerId(call.arguments['markerId']),
198+
MarkerId(call.arguments['markerId'] as String),
196199
));
197200
break;
198201
case 'marker#onDrag':
199202
_mapEventStreamController.add(MarkerDragEvent(
200203
mapId,
201204
LatLng.fromJson(call.arguments['position'])!,
202-
MarkerId(call.arguments['markerId']),
205+
MarkerId(call.arguments['markerId'] as String),
203206
));
204207
break;
205208
case 'marker#onDragEnd':
206209
_mapEventStreamController.add(MarkerDragEndEvent(
207210
mapId,
208211
LatLng.fromJson(call.arguments['position'])!,
209-
MarkerId(call.arguments['markerId']),
212+
MarkerId(call.arguments['markerId'] as String),
210213
));
211214
break;
212215
case 'infoWindow#onTap':
213216
_mapEventStreamController.add(InfoWindowTapEvent(
214217
mapId,
215-
MarkerId(call.arguments['markerId']),
218+
MarkerId(call.arguments['markerId'] as String),
216219
));
217220
break;
218221
case 'polyline#onTap':
219222
_mapEventStreamController.add(PolylineTapEvent(
220223
mapId,
221-
PolylineId(call.arguments['polylineId']),
224+
PolylineId(call.arguments['polylineId'] as String),
222225
));
223226
break;
224227
case 'polygon#onTap':
225228
_mapEventStreamController.add(PolygonTapEvent(
226229
mapId,
227-
PolygonId(call.arguments['polygonId']),
230+
PolygonId(call.arguments['polygonId'] as String),
228231
));
229232
break;
230233
case 'circle#onTap':
231234
_mapEventStreamController.add(CircleTapEvent(
232235
mapId,
233-
CircleId(call.arguments['circleId']),
236+
CircleId(call.arguments['circleId'] as String),
234237
));
235238
break;
236239
case 'groundOverlay#onTap':
@@ -254,17 +257,17 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
254257
case 'tileOverlay#getTile':
255258
final Map<TileOverlayId, TileOverlay>? tileOverlaysForThisMap =
256259
_tileOverlays[mapId];
257-
final String tileOverlayId = call.arguments['tileOverlayId'];
260+
final String tileOverlayId = call.arguments['tileOverlayId'] as String;
258261
final TileOverlay? tileOverlay =
259262
tileOverlaysForThisMap?[TileOverlayId(tileOverlayId)];
260-
TileProvider? tileProvider = tileOverlay?.tileProvider;
263+
final TileProvider? tileProvider = tileOverlay?.tileProvider;
261264
if (tileProvider == null) {
262265
return TileProvider.noTile.toJson();
263266
}
264267
final Tile tile = await tileProvider.getTile(
265-
call.arguments['x'],
266-
call.arguments['y'],
267-
call.arguments['zoom'],
268+
call.arguments['x'] as int,
269+
call.arguments['y'] as int,
270+
call.arguments['zoom'] as int?,
268271
);
269272
return tile.toJson();
270273
default:
@@ -341,7 +344,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
341344
}) {
342345
final Map<TileOverlayId, TileOverlay>? currentTileOverlays =
343346
_tileOverlays[mapId];
344-
Set<TileOverlay> previousSet = currentTileOverlays != null
347+
final Set<TileOverlay> previousSet = currentTileOverlays != null
345348
? currentTileOverlays.values.toSet()
346349
: <TileOverlay>{};
347350
final TileOverlayUpdates updates =
@@ -403,9 +406,9 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
403406
}) async {
404407
final List<dynamic> successAndError = (await channel(mapId)
405408
.invokeMethod<List<dynamic>>('map#setStyle', mapStyle))!;
406-
final bool success = successAndError[0];
409+
final bool success = successAndError[0] as bool;
407410
if (!success) {
408-
throw MapStyleException(successAndError[1]);
411+
throw MapStyleException(successAndError[1] as String);
409412
}
410413
}
411414

@@ -441,7 +444,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
441444
final List<dynamic> latLng = (await channel(mapId)
442445
.invokeMethod<List<dynamic>>(
443446
'map#getLatLng', screenCoordinate.toJson()))!;
444-
return LatLng(latLng[0], latLng[1]);
447+
return LatLng(latLng[0] as double, latLng[1] as double);
445448
}
446449

447450
@override

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
import 'dart:async';
66
import 'dart:typed_data';
77

8-
import 'package:flutter/widgets.dart';
9-
import 'package:flutter/services.dart';
10-
import 'package:flutter/material.dart';
118
import 'package:flutter/foundation.dart';
129
import 'package:flutter/gestures.dart';
13-
10+
import 'package:flutter/material.dart';
11+
import 'package:flutter/services.dart';
12+
import 'package:flutter/widgets.dart';
1413
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
1514
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
1615

@@ -379,8 +378,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
379378
Set<GroundOverlay> groundOverlays = const <GroundOverlay>{},
380379
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers =
381380
const <Factory<OneSequenceGestureRecognizer>>{},
382-
// TODO: Replace with a structured type that's part of the interface.
383-
// See https://github.com/flutter/flutter/issues/70330.
381+
// TODO(stuartmorgan): Replace with a structured type that's part of the
382+
// interface. See https://github.com/flutter/flutter/issues/70330.
384383
Map<String, dynamic> mapOptions = const <String, dynamic>{},
385384
}) {
386385
throw UnimplementedError('buildView() has not been implemented.');

0 commit comments

Comments
 (0)