Skip to content

Commit 99aa799

Browse files
authored
[google_maps_flutter] Updates platform interface to new analysis options (flutter#5793)
1 parent bbae271 commit 99aa799

40 files changed

+505
-430
lines changed

analysis_options.yaml

-4
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

-14
This file was deleted.

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

+2-1
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

-1
This file was deleted.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/google_maps_flutter_platform_interface.dart

+1-1
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

+9-9
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

+30-27
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}) {
@@ -180,52 +183,52 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
180183
case 'marker#onTap':
181184
_mapEventStreamController.add(MarkerTapEvent(
182185
mapId,
183-
MarkerId(call.arguments['markerId']),
186+
MarkerId(call.arguments['markerId'] as String),
184187
));
185188
break;
186189
case 'marker#onDragStart':
187190
_mapEventStreamController.add(MarkerDragStartEvent(
188191
mapId,
189192
LatLng.fromJson(call.arguments['position'])!,
190-
MarkerId(call.arguments['markerId']),
193+
MarkerId(call.arguments['markerId'] as String),
191194
));
192195
break;
193196
case 'marker#onDrag':
194197
_mapEventStreamController.add(MarkerDragEvent(
195198
mapId,
196199
LatLng.fromJson(call.arguments['position'])!,
197-
MarkerId(call.arguments['markerId']),
200+
MarkerId(call.arguments['markerId'] as String),
198201
));
199202
break;
200203
case 'marker#onDragEnd':
201204
_mapEventStreamController.add(MarkerDragEndEvent(
202205
mapId,
203206
LatLng.fromJson(call.arguments['position'])!,
204-
MarkerId(call.arguments['markerId']),
207+
MarkerId(call.arguments['markerId'] as String),
205208
));
206209
break;
207210
case 'infoWindow#onTap':
208211
_mapEventStreamController.add(InfoWindowTapEvent(
209212
mapId,
210-
MarkerId(call.arguments['markerId']),
213+
MarkerId(call.arguments['markerId'] as String),
211214
));
212215
break;
213216
case 'polyline#onTap':
214217
_mapEventStreamController.add(PolylineTapEvent(
215218
mapId,
216-
PolylineId(call.arguments['polylineId']),
219+
PolylineId(call.arguments['polylineId'] as String),
217220
));
218221
break;
219222
case 'polygon#onTap':
220223
_mapEventStreamController.add(PolygonTapEvent(
221224
mapId,
222-
PolygonId(call.arguments['polygonId']),
225+
PolygonId(call.arguments['polygonId'] as String),
223226
));
224227
break;
225228
case 'circle#onTap':
226229
_mapEventStreamController.add(CircleTapEvent(
227230
mapId,
228-
CircleId(call.arguments['circleId']),
231+
CircleId(call.arguments['circleId'] as String),
229232
));
230233
break;
231234
case 'map#onTap':
@@ -243,17 +246,17 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
243246
case 'tileOverlay#getTile':
244247
final Map<TileOverlayId, TileOverlay>? tileOverlaysForThisMap =
245248
_tileOverlays[mapId];
246-
final String tileOverlayId = call.arguments['tileOverlayId'];
249+
final String tileOverlayId = call.arguments['tileOverlayId'] as String;
247250
final TileOverlay? tileOverlay =
248251
tileOverlaysForThisMap?[TileOverlayId(tileOverlayId)];
249-
TileProvider? tileProvider = tileOverlay?.tileProvider;
252+
final TileProvider? tileProvider = tileOverlay?.tileProvider;
250253
if (tileProvider == null) {
251254
return TileProvider.noTile.toJson();
252255
}
253256
final Tile tile = await tileProvider.getTile(
254-
call.arguments['x'],
255-
call.arguments['y'],
256-
call.arguments['zoom'],
257+
call.arguments['x'] as int,
258+
call.arguments['y'] as int,
259+
call.arguments['zoom'] as int?,
257260
);
258261
return tile.toJson();
259262
default:
@@ -330,7 +333,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
330333
}) {
331334
final Map<TileOverlayId, TileOverlay>? currentTileOverlays =
332335
_tileOverlays[mapId];
333-
Set<TileOverlay> previousSet = currentTileOverlays != null
336+
final Set<TileOverlay> previousSet = currentTileOverlays != null
334337
? currentTileOverlays.values.toSet()
335338
: <TileOverlay>{};
336339
final TileOverlayUpdates updates =
@@ -380,9 +383,9 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
380383
}) async {
381384
final List<dynamic> successAndError = (await channel(mapId)
382385
.invokeMethod<List<dynamic>>('map#setStyle', mapStyle))!;
383-
final bool success = successAndError[0];
386+
final bool success = successAndError[0] as bool;
384387
if (!success) {
385-
throw MapStyleException(successAndError[1]);
388+
throw MapStyleException(successAndError[1] as String);
386389
}
387390
}
388391

@@ -418,7 +421,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
418421
final List<dynamic> latLng = (await channel(mapId)
419422
.invokeMethod<List<dynamic>>(
420423
'map#getLatLng', screenCoordinate.toJson()))!;
421-
return LatLng(latLng[0], latLng[1]);
424+
return LatLng(latLng[0] as double, latLng[1] as double);
422425
}
423426

424427
@override

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

+5-6
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

@@ -359,8 +358,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
359358
Set<TileOverlay> tileOverlays = const <TileOverlay>{},
360359
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers =
361360
const <Factory<OneSequenceGestureRecognizer>>{},
362-
// TODO: Replace with a structured type that's part of the interface.
363-
// See https://github.com/flutter/flutter/issues/70330.
361+
// TODO(stuartmorgan): Replace with a structured type that's part of the
362+
// interface. See https://github.com/flutter/flutter/issues/70330.
364363
Map<String, dynamic> mapOptions = const <String, dynamic>{},
365364
}) {
366365
throw UnimplementedError('buildView() has not been implemented.');

0 commit comments

Comments
 (0)