Skip to content

Commit

Permalink
[google_maps_flutter] Updates platform interface to new analysis opti…
Browse files Browse the repository at this point in the history
…ons (flutter#5793)
  • Loading branch information
stuartmorgan authored May 23, 2022
1 parent bbae271 commit 99aa799
Show file tree
Hide file tree
Showing 40 changed files with 505 additions and 430 deletions.
4 changes: 0 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
# with minimal changes for this repository. The goal is to move toward using a
# shared set of analysis options as much as possible, and eventually a shared
# file.
#
# Plugins that have not yet switched from the previous set of options have a
# local analysis_options.yaml that points to analysis_options_legacy.yaml
# instead.

# Specify analysis options.
#
Expand Down
14 changes: 0 additions & 14 deletions analysis_options_legacy.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.1.7

* Updates code for stricter analysis options.
* Removes unnecessary imports.

## 2.1.6
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'src/events/map_event.dart';
export 'src/method_channel/method_channel_google_maps_flutter.dart'
show MethodChannelGoogleMapsFlutter;
export 'src/platform_interface/google_maps_flutter_platform.dart';
export 'src/types/types.dart';
export 'src/events/map_event.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
/// events to access the `.position` property, rather than the more generic `.value`
/// yielded from the latter.
class MapEvent<T> {
/// The ID of the Map this event is associated to.
final int mapId;

/// The value wrapped by this event
final T value;

/// Build a Map Event, that relates a mapId with a given value.
///
/// The `mapId` is the id of the map that triggered the event.
/// `value` may be `null` in events that don't transport any meaningful data.
MapEvent(this.mapId, this.value);

/// The ID of the Map this event is associated to.
final int mapId;

/// The value wrapped by this event
final T value;
}

/// A `MapEvent` associated to a `position`.
class _PositionedMapEvent<T> extends MapEvent<T> {
/// The position where this event happened.
final LatLng position;

/// Build a Positioned MapEvent, that relates a mapId and a position with a value.
///
/// The `mapId` is the id of the map that triggered the event.
/// `value` may be `null` in events that don't transport any meaningful data.
_PositionedMapEvent(int mapId, this.position, T value) : super(mapId, value);

/// The position where this event happened.
final LatLng position;
}

// The following events are the ones exposed to the end user. They are semantic extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class UnknownMapIDError extends Error {
/// Message describing the assertion error.
final Object? message;

@override
String toString() {
if (message != null) {
return "Unknown map ID $mapId: ${Error.safeToString(message)}";
return 'Unknown map ID $mapId: ${Error.safeToString(message)}';
}
return "Unknown map ID $mapId";
return 'Unknown map ID $mapId';
}
}

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

/// Accesses the MethodChannel associated to the passed mapId.
MethodChannel channel(int mapId) {
MethodChannel? channel = _channels[mapId];
final MethodChannel? channel = _channels[mapId];
if (channel == null) {
throw UnknownMapIDError(mapId);
}
return channel;
}

// Keep a collection of mapId to a map of TileOverlays.
final Map<int, Map<TileOverlayId, TileOverlay>> _tileOverlays = {};
final Map<int, Map<TileOverlayId, TileOverlay>> _tileOverlays =
<int, Map<TileOverlayId, TileOverlay>>{};

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

@override
Future<void> init(int mapId) {
MethodChannel channel = ensureChannelInitialized(mapId);
final MethodChannel channel = ensureChannelInitialized(mapId);
return channel.invokeMethod<void>('map#waitForMap');
}

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

// Returns a filtered view of the events in the _controller, by mapId.
Stream<MapEvent> _events(int mapId) =>
_mapEventStreamController.stream.where((event) => event.mapId == mapId);
Stream<MapEvent<Object?>> _events(int mapId) =>
_mapEventStreamController.stream
.where((MapEvent<Object?> event) => event.mapId == mapId);

@override
Stream<CameraMoveStartedEvent> onCameraMoveStarted({required int mapId}) {
Expand Down Expand Up @@ -180,52 +183,52 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
case 'marker#onTap':
_mapEventStreamController.add(MarkerTapEvent(
mapId,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'marker#onDragStart':
_mapEventStreamController.add(MarkerDragStartEvent(
mapId,
LatLng.fromJson(call.arguments['position'])!,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'marker#onDrag':
_mapEventStreamController.add(MarkerDragEvent(
mapId,
LatLng.fromJson(call.arguments['position'])!,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'marker#onDragEnd':
_mapEventStreamController.add(MarkerDragEndEvent(
mapId,
LatLng.fromJson(call.arguments['position'])!,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'infoWindow#onTap':
_mapEventStreamController.add(InfoWindowTapEvent(
mapId,
MarkerId(call.arguments['markerId']),
MarkerId(call.arguments['markerId'] as String),
));
break;
case 'polyline#onTap':
_mapEventStreamController.add(PolylineTapEvent(
mapId,
PolylineId(call.arguments['polylineId']),
PolylineId(call.arguments['polylineId'] as String),
));
break;
case 'polygon#onTap':
_mapEventStreamController.add(PolygonTapEvent(
mapId,
PolygonId(call.arguments['polygonId']),
PolygonId(call.arguments['polygonId'] as String),
));
break;
case 'circle#onTap':
_mapEventStreamController.add(CircleTapEvent(
mapId,
CircleId(call.arguments['circleId']),
CircleId(call.arguments['circleId'] as String),
));
break;
case 'map#onTap':
Expand All @@ -243,17 +246,17 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
case 'tileOverlay#getTile':
final Map<TileOverlayId, TileOverlay>? tileOverlaysForThisMap =
_tileOverlays[mapId];
final String tileOverlayId = call.arguments['tileOverlayId'];
final String tileOverlayId = call.arguments['tileOverlayId'] as String;
final TileOverlay? tileOverlay =
tileOverlaysForThisMap?[TileOverlayId(tileOverlayId)];
TileProvider? tileProvider = tileOverlay?.tileProvider;
final TileProvider? tileProvider = tileOverlay?.tileProvider;
if (tileProvider == null) {
return TileProvider.noTile.toJson();
}
final Tile tile = await tileProvider.getTile(
call.arguments['x'],
call.arguments['y'],
call.arguments['zoom'],
call.arguments['x'] as int,
call.arguments['y'] as int,
call.arguments['zoom'] as int?,
);
return tile.toJson();
default:
Expand Down Expand Up @@ -330,7 +333,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
}) {
final Map<TileOverlayId, TileOverlay>? currentTileOverlays =
_tileOverlays[mapId];
Set<TileOverlay> previousSet = currentTileOverlays != null
final Set<TileOverlay> previousSet = currentTileOverlays != null
? currentTileOverlays.values.toSet()
: <TileOverlay>{};
final TileOverlayUpdates updates =
Expand Down Expand Up @@ -380,9 +383,9 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
}) async {
final List<dynamic> successAndError = (await channel(mapId)
.invokeMethod<List<dynamic>>('map#setStyle', mapStyle))!;
final bool success = successAndError[0];
final bool success = successAndError[0] as bool;
if (!success) {
throw MapStyleException(successAndError[1]);
throw MapStyleException(successAndError[1] as String);
}
}

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

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import 'dart:async';
import 'dart:typed_data';

import 'package:flutter/widgets.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

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

0 comments on commit 99aa799

Please sign in to comment.