From 65de03a4cdd7bd261fe7c394e82a928dbb41703d Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 8 Feb 2021 11:19:08 -0500 Subject: [PATCH 01/14] WIP --- .../lib/src/events/map_event.dart | 10 +++++----- .../method_channel_google_maps_flutter.dart | 6 +++--- .../lib/src/types/bitmap.dart | 8 +++++--- .../lib/src/types/camera.dart | 6 +++++- .../lib/src/types/circle.dart | 2 +- .../lib/src/types/marker.dart | 4 ++-- .../lib/src/types/polygon.dart | 2 +- .../lib/src/types/polyline.dart | 2 +- .../lib/src/types/tile.dart | 2 +- .../lib/src/types/tile_overlay.dart | 2 +- .../lib/src/types/tile_provider.dart | 2 +- .../lib/src/types/utils/circle.dart | 2 +- .../lib/src/types/utils/marker.dart | 2 +- .../lib/src/types/utils/polygon.dart | 2 +- .../lib/src/types/utils/polyline.dart | 2 +- .../lib/src/types/utils/tile_overlay.dart | 6 +++--- .../pubspec.yaml | 6 +++--- 17 files changed, 36 insertions(+), 30 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart index c462b4b182e2..10eb74187460 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart @@ -51,7 +51,7 @@ class MapEvent { /// A `MapEvent` associated to a `position`. class _PositionedMapEvent extends MapEvent { /// The position where this event happened. - final LatLng position; + final LatLng/*!*/ position; /// Build a Positioned MapEvent, that relates a mapId and a position with a value. /// @@ -73,11 +73,11 @@ class CameraMoveStartedEvent extends MapEvent { } /// An event fired while the Camera of a [mapId] moves. -class CameraMoveEvent extends MapEvent { +class CameraMoveEvent extends MapEvent { /// Build a CameraMove Event triggered from the map represented by `mapId`. /// /// The `value` of this event is a [CameraPosition] object with the current position of the Camera. - CameraMoveEvent(int mapId, CameraPosition position) : super(mapId, position); + CameraMoveEvent(int mapId, CameraPosition/*!*/ position) : super(mapId, position); } /// An event fired when the Camera of a [mapId] becomes idle. @@ -141,7 +141,7 @@ class MapTapEvent extends _PositionedMapEvent { /// Build an MapTap Event triggered from the map represented by `mapId`. /// /// The `position` of this event is the LatLng where the Map was tapped. - MapTapEvent(int mapId, LatLng position) : super(mapId, position, null); + MapTapEvent(int mapId, LatLng/*!*/ position) : super(mapId, position, null); } /// An event fired when a Map is long pressed. @@ -149,5 +149,5 @@ class MapLongPressEvent extends _PositionedMapEvent { /// Build an MapTap Event triggered from the map represented by `mapId`. /// /// The `position` of this event is the LatLng where the Map was long pressed. - MapLongPressEvent(int mapId, LatLng position) : super(mapId, position, null); + MapLongPressEvent(int mapId, LatLng/*!*/ position) : super(mapId, position, null); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index 8b7af2cc3515..6bc3c0cedb29 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -28,7 +28,7 @@ import '../types/utils/tile_overlay.dart'; class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { // Keep a collection of id -> channel // Every method call passes the int mapId - final Map _channels = {}; + final Map _channels = {}; /// Accesses the MethodChannel associated to the passed mapId. MethodChannel channel(int mapId) { @@ -43,8 +43,8 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// This method is called when the plugin is first initialized. @override Future init(int mapId) { - MethodChannel channel; - if (!_channels.containsKey(mapId)) { + MethodChannel channel = _channels[mapId]; + if (channel == null) { channel = MethodChannel('plugins.flutter.io/google_maps_$mapId'); channel.setMethodCallHandler( (MethodCall call) => _handleMethodCall(call, mapId)); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart index e10481e321f5..4635df49adbc 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart @@ -4,6 +4,7 @@ import 'dart:async' show Future; import 'dart:typed_data' show Uint8List; +import 'dart:ui' show Size; import 'package:flutter/material.dart' show ImageConfiguration, AssetImage, AssetBundleImageKey; @@ -110,14 +111,15 @@ class BitmapDescriptor { AssetImage(assetName, package: package, bundle: bundle); final AssetBundleImageKey assetBundleImageKey = await assetImage.obtainKey(configuration); + final Size size = configuration?.size; return BitmapDescriptor._([ _fromAssetImage, assetBundleImageKey.name, assetBundleImageKey.scale, - if (kIsWeb && configuration?.size != null) + if (kIsWeb && size != null) [ - configuration.size.width, - configuration.size.height, + size.width, + size.height, ], ]); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart index 10ea1e98846a..48cde883060c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart @@ -77,9 +77,13 @@ class CameraPosition { if (json == null) { return null; } + final LatLng target = LatLng.fromJson(json['target']); + if (target == null) { + return null; + } return CameraPosition( bearing: json['bearing'], - target: LatLng.fromJson(json['target']), + target: target, tilt: json['tilt'], zoom: json['zoom'], ); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart index d1418a4c30b1..20f02da7885c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart @@ -127,7 +127,7 @@ class Circle { dynamic toJson() { final Map json = {}; - void addIfPresent(String fieldName, dynamic value) { + void addIfPresent(String fieldName, Object/*?*/ value) { if (value != null) { json[fieldName] = value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart index 9b57f9676334..64bbe0f2b433 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart @@ -69,7 +69,7 @@ class InfoWindow { dynamic _toJson() { final Map json = {}; - void addIfPresent(String fieldName, dynamic value) { + void addIfPresent(String fieldName, Object/*?*/ value) { if (value != null) { json[fieldName] = value; } @@ -271,7 +271,7 @@ class Marker { Map toJson() { final Map json = {}; - void addIfPresent(String fieldName, dynamic value) { + void addIfPresent(String fieldName, Object/*?*/ value) { if (value != null) { json[fieldName] = value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart index 96b39157418d..c111f26d93a6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart @@ -147,7 +147,7 @@ class Polygon { dynamic toJson() { final Map json = {}; - void addIfPresent(String fieldName, dynamic value) { + void addIfPresent(String fieldName, Object/*?*/ value) { if (value != null) { json[fieldName] = value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart index ae5c3b976352..81cc95319a89 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart @@ -177,7 +177,7 @@ class Polyline { dynamic toJson() { final Map json = {}; - void addIfPresent(String fieldName, dynamic value) { + void addIfPresent(String fieldName, Object/*?*/ value) { if (value != null) { json[fieldName] = value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart index a992b41fb6c0..a270ef6cf38f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart @@ -27,7 +27,7 @@ class Tile { Map toJson() { final Map json = {}; - void addIfPresent(String fieldName, dynamic value) { + void addIfPresent(String fieldName, Object/*?*/ value) { if (value != null) { json[fieldName] = value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart index 3978f23f05f8..f182d43ce2d8 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart @@ -125,7 +125,7 @@ class TileOverlay { Map toJson() { final Map json = {}; - void addIfPresent(String fieldName, dynamic value) { + void addIfPresent(String fieldName, Object/*?*/ value) { if (value != null) { json[fieldName] = value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_provider.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_provider.dart index c3c4f807e283..50088d84243c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_provider.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_provider.dart @@ -12,5 +12,5 @@ abstract class TileProvider { /// Returns the tile to be used for this tile coordinate. /// /// See [TileOverlay] for the specification of tile coordinates. - Future getTile(int x, int y, int zoom); + Future getTile(int/*!*/ x, int/*!*/ y, int zoom); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart index 5c3af96f8e02..6a132fe83561 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart @@ -14,7 +14,7 @@ Map keyByCircleId(Iterable circles) { } /// Converts a Set of Circles into something serializable in JSON. -List> serializeCircleSet(Set circles) { +List> serializeCircleSet(Set/*!*/ circles) { if (circles == null) { return null; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart index 7a2c76d8055b..9f3450fcc0e6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart @@ -14,7 +14,7 @@ Map keyByMarkerId(Iterable markers) { } /// Converts a Set of Markers into something serializable in JSON. -List> serializeMarkerSet(Set markers) { +List> serializeMarkerSet(Set/*!*/ markers) { if (markers == null) { return null; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart index 9434ddaa077d..7d4a5b7188df 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart @@ -14,7 +14,7 @@ Map keyByPolygonId(Iterable polygons) { } /// Converts a Set of Polygons into something serializable in JSON. -List> serializePolygonSet(Set polygons) { +List> serializePolygonSet(Set/*!*/ polygons) { if (polygons == null) { return null; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart index 9cef6319ddb5..8d1cd74ec284 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart @@ -15,7 +15,7 @@ Map keyByPolylineId(Iterable polylines) { } /// Converts a Set of Polylines into something serializable in JSON. -List> serializePolylineSet(Set polylines) { +List> serializePolylineSet(Set/*!*/ polylines) { if (polylines == null) { return null; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart index 0736c836481f..0c817fd2150c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart @@ -1,8 +1,8 @@ import '../types.dart'; /// Converts an [Iterable] of TileOverlay in a Map of TileOverlayId -> TileOverlay. -Map keyTileOverlayId( - Iterable tileOverlays) { +Map keyTileOverlayId( + Iterable/*!*/ tileOverlays) { if (tileOverlays == null) { return {}; } @@ -13,7 +13,7 @@ Map keyTileOverlayId( /// Converts a Set of TileOverlays into something serializable in JSON. List> serializeTileOverlaySet( - Set tileOverlays) { + Set/*!*/ tileOverlays) { if (tileOverlays == null) { return null; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml index 487a54b08e5e..c62b7a9ebbeb 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml @@ -9,14 +9,14 @@ dependencies: flutter: sdk: flutter meta: ^1.0.5 - plugin_platform_interface: ^1.0.1 - stream_transform: ^1.2.0 + plugin_platform_interface: ^1.1.0-nullsafety.2 + stream_transform: ^2.0.0-nullsafety.0 collection: ^1.14.13 dev_dependencies: flutter_test: sdk: flutter - mockito: ^4.1.1 + mockito: ^5.0.0-nullsafety.0 pedantic: ^1.8.0 environment: From cb98e0cbf2b8a80cbd7ac0dc63c1c82ae168b319 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 8 Feb 2021 15:34:31 -0500 Subject: [PATCH 02/14] WIP2 --- .../lib/src/types/bitmap.dart | 2 +- .../lib/src/types/circle.dart | 28 +--- .../lib/src/types/circle_updates.dart | 97 +------------ .../lib/src/types/location.dart | 14 +- .../lib/src/types/maps_object.dart | 49 +++++++ .../lib/src/types/maps_object_updates.dart | 135 ++++++++++++++++++ .../lib/src/types/marker.dart | 28 +--- .../lib/src/types/marker_updates.dart | 97 +------------ .../lib/src/types/polygon.dart | 28 +--- .../lib/src/types/polygon_updates.dart | 97 +------------ .../lib/src/types/polyline.dart | 28 +--- .../lib/src/types/polyline_updates.dart | 98 +------------ .../lib/src/types/tile_overlay.dart | 33 ++--- .../lib/src/types/tile_overlay_updates.dart | 112 +-------------- .../lib/src/types/types.dart | 2 + .../lib/src/types/utils/circle.dart | 14 +- .../lib/src/types/utils/maps_object.dart | 25 ++++ .../lib/src/types/utils/marker.dart | 14 +- .../lib/src/types/utils/polygon.dart | 14 +- .../lib/src/types/utils/polyline.dart | 17 +-- .../lib/src/types/utils/tile_overlay.dart | 21 ++- .../test/types/tile_overlay_test.dart | 2 +- .../test/types/tile_overlay_updates_test.dart | 6 +- 23 files changed, 308 insertions(+), 653 deletions(-) create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart index 4635df49adbc..bf5b94d14e45 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart @@ -134,7 +134,7 @@ class BitmapDescriptor { // This is needed in Web to re-hydrate BitmapDescriptors that have been // transformed to JSON for transport. // TODO(https://github.com/flutter/flutter/issues/70330): Clean this up. - BitmapDescriptor.fromJson(dynamic json) : _json = json { + BitmapDescriptor.fromJson(Object json) : _json = json { assert(_validTypes.contains(_json[0])); switch (_json[0]) { case _defaultMarker: diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart index 20f02da7885c..f9aca33da986 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart @@ -12,33 +12,14 @@ import 'types.dart'; /// /// This does not have to be globally unique, only unique among the list. @immutable -class CircleId { +class CircleId extends MapsObjectId { /// Creates an immutable identifier for a [Circle]. - CircleId(this.value) : assert(value != null); - - /// value of the [CircleId]. - final String value; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final CircleId typedOther = other; - return value == typedOther.value; - } - - @override - int get hashCode => value.hashCode; - - @override - String toString() { - return 'CircleId{value: $value}'; - } + CircleId(String value) : super(value); } /// Draws a circle on the map. @immutable -class Circle { +class Circle implements MapsObject { /// Creates an immutable representation of a [Circle] to draw on [GoogleMap]. const Circle({ @required this.circleId, @@ -56,6 +37,9 @@ class Circle { /// Uniquely identifies a [Circle]. final CircleId circleId; + @override + CircleId get mapsId => circleId; + /// True if the [Circle] consumes tap events. /// /// If this is false, [onTap] callback will not be triggered. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart index 6f494423a38f..470db36b96ac 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart @@ -2,109 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show hashValues; - -import 'package:flutter/foundation.dart' show setEquals; - import 'types.dart'; -import 'utils/circle.dart'; /// [Circle] update events to be applied to the [GoogleMap]. /// /// Used in [GoogleMapController] when the map is updated. // (Do not re-export) -class CircleUpdates { +class CircleUpdates extends MapsObjectUpdates { /// Computes [CircleUpdates] given previous and current [Circle]s. - CircleUpdates.from(Set previous, Set current) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - - final Map previousCircles = keyByCircleId(previous); - final Map currentCircles = keyByCircleId(current); - - final Set prevCircleIds = previousCircles.keys.toSet(); - final Set currentCircleIds = currentCircles.keys.toSet(); - - Circle idToCurrentCircle(CircleId id) { - return currentCircles[id]; - } - - final Set _circleIdsToRemove = - prevCircleIds.difference(currentCircleIds); - - final Set _circlesToAdd = currentCircleIds - .difference(prevCircleIds) - .map(idToCurrentCircle) - .toSet(); - - /// Returns `true` if [current] is not equals to previous one with the - /// same id. - bool hasChanged(Circle current) { - final Circle previous = previousCircles[current.circleId]; - return current != previous; - } - - final Set _circlesToChange = currentCircleIds - .intersection(prevCircleIds) - .map(idToCurrentCircle) - .where(hasChanged) - .toSet(); - - circlesToAdd = _circlesToAdd; - circleIdsToRemove = _circleIdsToRemove; - circlesToChange = _circlesToChange; - } + CircleUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'circle'); /// Set of Circles to be added in this update. - Set circlesToAdd; + Set get circlesToAdd => objectsToAdd; /// Set of CircleIds to be removed in this update. - Set circleIdsToRemove; + Set/*?*/ get circleIdsToRemove => objectIdsToRemove.cast(); /// Set of Circles to be changed in this update. - Set circlesToChange; - - /// Converts this object to something serializable in JSON. - Map toJson() { - final Map updateMap = {}; - - void addIfNonNull(String fieldName, dynamic value) { - if (value != null) { - updateMap[fieldName] = value; - } - } - - addIfNonNull('circlesToAdd', serializeCircleSet(circlesToAdd)); - addIfNonNull('circlesToChange', serializeCircleSet(circlesToChange)); - addIfNonNull('circleIdsToRemove', - circleIdsToRemove.map((CircleId m) => m.value).toList()); - - return updateMap; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final CircleUpdates typedOther = other; - return setEquals(circlesToAdd, typedOther.circlesToAdd) && - setEquals(circleIdsToRemove, typedOther.circleIdsToRemove) && - setEquals(circlesToChange, typedOther.circlesToChange); - } - - @override - int get hashCode => - hashValues(circlesToAdd, circleIdsToRemove, circlesToChange); - - @override - String toString() { - return '_CircleUpdates{circlesToAdd: $circlesToAdd, ' - 'circleIdsToRemove: $circleIdsToRemove, ' - 'circlesToChange: $circlesToChange}'; - } + Set get circlesToChange => objectsToChange; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart index 6b76a6d496ac..d2b736ce682b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart @@ -34,11 +34,13 @@ class LatLng { } /// Initialize a LatLng from an \[lat, lng\] array. - static LatLng fromJson(dynamic json) { + static LatLng fromJson(Object json) { if (json == null) { return null; } - return LatLng(json[0], json[1]); + assert(json is List && json.length == 2); + final list = json as List; + return LatLng(list[0], list[1]); } @override @@ -102,13 +104,15 @@ class LatLngBounds { /// Converts a list to [LatLngBounds]. @visibleForTesting - static LatLngBounds fromList(dynamic json) { + static LatLngBounds/*?*/ fromList(Object/*?*/ json) { if (json == null) { return null; } + assert(json is List && json.length == 2); + final list = json as List; return LatLngBounds( - southwest: LatLng.fromJson(json[0]), - northeast: LatLng.fromJson(json[1]), + southwest: LatLng.fromJson(list[0]), + northeast: LatLng.fromJson(list[1]), ); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart new file mode 100644 index 000000000000..8566e02cb510 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart @@ -0,0 +1,49 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show objectRuntimeType; +import 'package:meta/meta.dart' show immutable; + +/// Uniquely identifies object an among [GoogleMap] collections of a specific +/// type. +/// +/// This does not have to be globally unique, only unique among the collection. +@immutable +class MapsObjectId { + /// Creates an immutable object representing a [T] among [GoogleMap] Ts. + /// + /// An [AssertionError] will be thrown if [value] is null. + MapsObjectId(this.value) : assert(value != null); + + /// The value of the id. + final String value; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + if (other.runtimeType != runtimeType) return false; + final MapsObjectId typedOther = other; + return value == typedOther.value; + } + + @override + int get hashCode => value.hashCode; + + @override + String toString() { + return '${objectRuntimeType(this, 'MapsObjectId')}{value: $value}'; + } +} + +/// A common interface for maps types. +abstract class MapsObject { + /// A identifier for this object. + MapsObjectId get mapsId; + + /// Returns a duplicate of this object. + T clone(); + + /// Converts this object to something serializable in JSON. + dynamic toJson(); +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart new file mode 100644 index 000000000000..16a655e079b9 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart @@ -0,0 +1,135 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show hashValues, hashList; + +import 'package:flutter/foundation.dart' show objectRuntimeType, setEquals; +import 'package:meta/meta.dart' show required; + +import 'maps_object.dart'; +import 'utils/maps_object.dart'; + +/// Update specification for a set of objects. +class MapsObjectUpdates { + /// Computes updates given previous and current object sets. + /// + /// [objectName] is the prefix to use when serializing the updates into a JSON + /// dictionary. E.g., 'circle' will give 'circlesToAdd', 'circlesToUpdate', + /// 'circleIdsToRemove'. + MapsObjectUpdates.from( + Set previous, + Set current, { + @required this.objectName, + }) { + if (previous == null) { + previous = Set.identity(); + } + + if (current == null) { + current = Set.identity(); + } + + final Map, T> previousObjects = keyByMapsObjectId(previous); + final Map, T> currentObjects = keyByMapsObjectId(current); + + final Set> previousObjectIds = previousObjects.keys.toSet(); + final Set> currentObjectIds = currentObjects.keys.toSet(); + + /// Maps an ID back to a [T] in [currentObjects]. + /// + /// It is a programming error to call this with an ID that is not guaranteed + /// to be in [currentObjects]. + T _idToCurrentObject(MapsObjectId id) { + return currentObjects[id]; + } + + _objectIdsToRemove = previousObjectIds.difference(currentObjectIds); + + _objectsToAdd = currentObjectIds + .difference(previousObjectIds) + .map(_idToCurrentObject) + .toSet(); + + // Returns `true` if [current] is not equals to previous one with the + // same id. + bool hasChanged(T current) { + final T previous = previousObjects[current.mapsId]; + return current != previous; + } + + _objectsToChange = currentObjectIds + .intersection(previousObjectIds) + .map(_idToCurrentObject) + .where(hasChanged) + .toSet(); + } + + /// The name of the objects being updated, for use in serialization. + final String objectName; + + /// Set of objects to be added in this update. + Set get objectsToAdd { + return _objectsToAdd; + } + + Set _objectsToAdd; + + /// Set of objects to be removed in this update. + Set> get objectIdsToRemove { + return _objectIdsToRemove; + } + + Set> _objectIdsToRemove; + + /// Set of objects to be changed in this update. + Set get objectsToChange { + return _objectsToChange; + } + + Set _objectsToChange; + + /// Converts this object to JSON. + Map toJson() { + final Map updateMap = {}; + + void addIfNonNull(String fieldName, Object /*?*/ value) { + if (value != null) { + updateMap[fieldName] = value; + } + } + + addIfNonNull('${objectName}sToAdd', serializeMapsObjectSet(_objectsToAdd)); + addIfNonNull( + '${objectName}sToChange', serializeMapsObjectSet(_objectsToChange)); + addIfNonNull( + '${objectName}IdsToRemove', + _objectIdsToRemove + .map((MapsObjectId m) => m.value) + .toList()); + + return updateMap; + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is MapsObjectUpdates && + setEquals(_objectsToAdd, other._objectsToAdd) && + setEquals(_objectIdsToRemove, other._objectIdsToRemove) && + setEquals(_objectsToChange, other._objectsToChange); + } + + @override + int get hashCode => hashValues(hashList(_objectsToAdd), + hashList(_objectIdsToRemove), hashList(_objectsToChange)); + + @override + String toString() { + return '${objectRuntimeType(this, 'MapsObjectUpdates')}{add: $objectsToAdd, ' + 'remove: $objectIdsToRemove, ' + 'change: $objectsToChange}'; + } +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart index 64bbe0f2b433..4969e5edb1e1 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart @@ -105,28 +105,9 @@ class InfoWindow { /// /// This does not have to be globally unique, only unique among the list. @immutable -class MarkerId { +class MarkerId extends MapsObjectId { /// Creates an immutable identifier for a [Marker]. - MarkerId(this.value) : assert(value != null); - - /// value of the [MarkerId]. - final String value; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final MarkerId typedOther = other; - return value == typedOther.value; - } - - @override - int get hashCode => value.hashCode; - - @override - String toString() { - return 'MarkerId{value: $value}'; - } + MarkerId(String value) : super(value); } /// Marks a geographical location on the map. @@ -135,7 +116,7 @@ class MarkerId { /// the map's surface; that is, it will not necessarily change orientation /// due to map rotations, tilting, or zooming. @immutable -class Marker { +class Marker implements MapsObject { /// Creates a set of marker configuration options. /// /// Default marker options. @@ -175,6 +156,9 @@ class Marker { /// Uniquely identifies a [Marker]. final MarkerId markerId; + @override + MarkerId get mapsId => markerId; + /// The opacity of the marker, between 0.0 and 1.0 inclusive. /// /// 0.0 means fully transparent, 1.0 means fully opaque. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker_updates.dart index bb6ea8813ea3..1675b5272718 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker_updates.dart @@ -2,109 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show hashValues; - -import 'package:flutter/foundation.dart' show setEquals; - import 'types.dart'; -import 'utils/marker.dart'; /// [Marker] update events to be applied to the [GoogleMap]. /// /// Used in [GoogleMapController] when the map is updated. // (Do not re-export) -class MarkerUpdates { +class MarkerUpdates extends MapsObjectUpdates { /// Computes [MarkerUpdates] given previous and current [Marker]s. - MarkerUpdates.from(Set previous, Set current) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - - final Map previousMarkers = keyByMarkerId(previous); - final Map currentMarkers = keyByMarkerId(current); - - final Set prevMarkerIds = previousMarkers.keys.toSet(); - final Set currentMarkerIds = currentMarkers.keys.toSet(); - - Marker idToCurrentMarker(MarkerId id) { - return currentMarkers[id]; - } - - final Set _markerIdsToRemove = - prevMarkerIds.difference(currentMarkerIds); - - final Set _markersToAdd = currentMarkerIds - .difference(prevMarkerIds) - .map(idToCurrentMarker) - .toSet(); - - /// Returns `true` if [current] is not equals to previous one with the - /// same id. - bool hasChanged(Marker current) { - final Marker previous = previousMarkers[current.markerId]; - return current != previous; - } - - final Set _markersToChange = currentMarkerIds - .intersection(prevMarkerIds) - .map(idToCurrentMarker) - .where(hasChanged) - .toSet(); - - markersToAdd = _markersToAdd; - markerIdsToRemove = _markerIdsToRemove; - markersToChange = _markersToChange; - } + MarkerUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'marker'); /// Set of Markers to be added in this update. - Set markersToAdd; + Set get markersToAdd => objectsToAdd; /// Set of MarkerIds to be removed in this update. - Set markerIdsToRemove; + Set get markerIdsToRemove => objectIdsToRemove.cast(); /// Set of Markers to be changed in this update. - Set markersToChange; - - /// Converts this object to something serializable in JSON. - Map toJson() { - final Map updateMap = {}; - - void addIfNonNull(String fieldName, dynamic value) { - if (value != null) { - updateMap[fieldName] = value; - } - } - - addIfNonNull('markersToAdd', serializeMarkerSet(markersToAdd)); - addIfNonNull('markersToChange', serializeMarkerSet(markersToChange)); - addIfNonNull('markerIdsToRemove', - markerIdsToRemove.map((MarkerId m) => m.value).toList()); - - return updateMap; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final MarkerUpdates typedOther = other; - return setEquals(markersToAdd, typedOther.markersToAdd) && - setEquals(markerIdsToRemove, typedOther.markerIdsToRemove) && - setEquals(markersToChange, typedOther.markersToChange); - } - - @override - int get hashCode => - hashValues(markersToAdd, markerIdsToRemove, markersToChange); - - @override - String toString() { - return '_MarkerUpdates{markersToAdd: $markersToAdd, ' - 'markerIdsToRemove: $markerIdsToRemove, ' - 'markersToChange: $markersToChange}'; - } + Set get markersToChange => objectsToChange; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart index c111f26d93a6..504464c9b090 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart @@ -13,33 +13,14 @@ import 'types.dart'; /// /// This does not have to be globally unique, only unique among the list. @immutable -class PolygonId { +class PolygonId extends MapsObjectId { /// Creates an immutable identifier for a [Polygon]. - PolygonId(this.value) : assert(value != null); - - /// value of the [PolygonId]. - final String value; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final PolygonId typedOther = other; - return value == typedOther.value; - } - - @override - int get hashCode => value.hashCode; - - @override - String toString() { - return 'PolygonId{value: $value}'; - } + PolygonId(String value) : super(value); } /// Draws a polygon through geographical locations on the map. @immutable -class Polygon { +class Polygon implements MapsObject { /// Creates an immutable representation of a polygon through geographical locations on the map. const Polygon({ @required this.polygonId, @@ -58,6 +39,9 @@ class Polygon { /// Uniquely identifies a [Polygon]. final PolygonId polygonId; + @override + PolygonId get mapsId => polygonId; + /// True if the [Polygon] consumes tap events. /// /// If this is false, [onTap] callback will not be triggered. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon_updates.dart index cc8b8e26c896..6b9ac7957936 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon_updates.dart @@ -2,109 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show hashValues; - -import 'package:flutter/foundation.dart' show setEquals; - import 'types.dart'; -import 'utils/polygon.dart'; /// [Polygon] update events to be applied to the [GoogleMap]. /// /// Used in [GoogleMapController] when the map is updated. // (Do not re-export) -class PolygonUpdates { +class PolygonUpdates extends MapsObjectUpdates { /// Computes [PolygonUpdates] given previous and current [Polygon]s. - PolygonUpdates.from(Set previous, Set current) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - - final Map previousPolygons = keyByPolygonId(previous); - final Map currentPolygons = keyByPolygonId(current); - - final Set prevPolygonIds = previousPolygons.keys.toSet(); - final Set currentPolygonIds = currentPolygons.keys.toSet(); - - Polygon idToCurrentPolygon(PolygonId id) { - return currentPolygons[id]; - } - - final Set _polygonIdsToRemove = - prevPolygonIds.difference(currentPolygonIds); - - final Set _polygonsToAdd = currentPolygonIds - .difference(prevPolygonIds) - .map(idToCurrentPolygon) - .toSet(); - - /// Returns `true` if [current] is not equals to previous one with the - /// same id. - bool hasChanged(Polygon current) { - final Polygon previous = previousPolygons[current.polygonId]; - return current != previous; - } - - final Set _polygonsToChange = currentPolygonIds - .intersection(prevPolygonIds) - .map(idToCurrentPolygon) - .where(hasChanged) - .toSet(); - - polygonsToAdd = _polygonsToAdd; - polygonIdsToRemove = _polygonIdsToRemove; - polygonsToChange = _polygonsToChange; - } + PolygonUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'polygon'); /// Set of Polygons to be added in this update. - Set polygonsToAdd; + Set get polygonsToAdd => objectsToAdd; /// Set of PolygonIds to be removed in this update. - Set polygonIdsToRemove; + Set get polygonIdsToRemove => objectIdsToRemove.cast(); /// Set of Polygons to be changed in this update. - Set polygonsToChange; - - /// Converts this object to something serializable in JSON. - Map toJson() { - final Map updateMap = {}; - - void addIfNonNull(String fieldName, dynamic value) { - if (value != null) { - updateMap[fieldName] = value; - } - } - - addIfNonNull('polygonsToAdd', serializePolygonSet(polygonsToAdd)); - addIfNonNull('polygonsToChange', serializePolygonSet(polygonsToChange)); - addIfNonNull('polygonIdsToRemove', - polygonIdsToRemove.map((PolygonId m) => m.value).toList()); - - return updateMap; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final PolygonUpdates typedOther = other; - return setEquals(polygonsToAdd, typedOther.polygonsToAdd) && - setEquals(polygonIdsToRemove, typedOther.polygonIdsToRemove) && - setEquals(polygonsToChange, typedOther.polygonsToChange); - } - - @override - int get hashCode => - hashValues(polygonsToAdd, polygonIdsToRemove, polygonsToChange); - - @override - String toString() { - return '_PolygonUpdates{polygonsToAdd: $polygonsToAdd, ' - 'polygonIdsToRemove: $polygonIdsToRemove, ' - 'polygonsToChange: $polygonsToChange}'; - } + Set get polygonsToChange => objectsToChange; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart index 81cc95319a89..c4fd8273f127 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart @@ -12,35 +12,16 @@ import 'types.dart'; /// /// This does not have to be globally unique, only unique among the list. @immutable -class PolylineId { +class PolylineId extends MapsObjectId { /// Creates an immutable object representing a [PolylineId] among [GoogleMap] polylines. /// /// An [AssertionError] will be thrown if [value] is null. - PolylineId(this.value) : assert(value != null); - - /// value of the [PolylineId]. - final String value; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final PolylineId typedOther = other; - return value == typedOther.value; - } - - @override - int get hashCode => value.hashCode; - - @override - String toString() { - return 'PolylineId{value: $value}'; - } + PolylineId(String value) : super(value); } /// Draws a line through geographical locations on the map. @immutable -class Polyline { +class Polyline implements MapsObject { /// Creates an immutable object representing a line drawn through geographical locations on the map. const Polyline({ @required this.polylineId, @@ -61,6 +42,9 @@ class Polyline { /// Uniquely identifies a [Polyline]. final PolylineId polylineId; + @override + PolylineId get mapsId => polylineId; + /// True if the [Polyline] consumes tap events. /// /// If this is false, [onTap] callback will not be triggered. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline_updates.dart index f871928c0ac4..1ae4017d9c45 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline_updates.dart @@ -2,110 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show hashValues; - -import 'package:flutter/foundation.dart' show setEquals; - -import 'utils/polyline.dart'; import 'types.dart'; /// [Polyline] update events to be applied to the [GoogleMap]. /// /// Used in [GoogleMapController] when the map is updated. // (Do not re-export) -class PolylineUpdates { +class PolylineUpdates extends MapsObjectUpdates { /// Computes [PolylineUpdates] given previous and current [Polyline]s. - PolylineUpdates.from(Set previous, Set current) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - - final Map previousPolylines = - keyByPolylineId(previous); - final Map currentPolylines = keyByPolylineId(current); - - final Set prevPolylineIds = previousPolylines.keys.toSet(); - final Set currentPolylineIds = currentPolylines.keys.toSet(); - - Polyline idToCurrentPolyline(PolylineId id) { - return currentPolylines[id]; - } - - final Set _polylineIdsToRemove = - prevPolylineIds.difference(currentPolylineIds); - - final Set _polylinesToAdd = currentPolylineIds - .difference(prevPolylineIds) - .map(idToCurrentPolyline) - .toSet(); - - /// Returns `true` if [current] is not equals to previous one with the - /// same id. - bool hasChanged(Polyline current) { - final Polyline previous = previousPolylines[current.polylineId]; - return current != previous; - } - - final Set _polylinesToChange = currentPolylineIds - .intersection(prevPolylineIds) - .map(idToCurrentPolyline) - .where(hasChanged) - .toSet(); - - polylinesToAdd = _polylinesToAdd; - polylineIdsToRemove = _polylineIdsToRemove; - polylinesToChange = _polylinesToChange; - } + PolylineUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'polyline'); /// Set of Polylines to be added in this update. - Set polylinesToAdd; + Set get polylinesToAdd => objectsToAdd; /// Set of PolylineIds to be removed in this update. - Set polylineIdsToRemove; + Set get polylineIdsToRemove => objectIdsToRemove.cast(); /// Set of Polylines to be changed in this update. - Set polylinesToChange; - - /// Converts this object to something serializable in JSON. - Map toJson() { - final Map updateMap = {}; - - void addIfNonNull(String fieldName, dynamic value) { - if (value != null) { - updateMap[fieldName] = value; - } - } - - addIfNonNull('polylinesToAdd', serializePolylineSet(polylinesToAdd)); - addIfNonNull('polylinesToChange', serializePolylineSet(polylinesToChange)); - addIfNonNull('polylineIdsToRemove', - polylineIdsToRemove.map((PolylineId m) => m.value).toList()); - - return updateMap; - } - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final PolylineUpdates typedOther = other; - return setEquals(polylinesToAdd, typedOther.polylinesToAdd) && - setEquals(polylineIdsToRemove, typedOther.polylineIdsToRemove) && - setEquals(polylinesToChange, typedOther.polylinesToChange); - } - - @override - int get hashCode => - hashValues(polylinesToAdd, polylineIdsToRemove, polylinesToChange); - - @override - String toString() { - return '_PolylineUpdates{polylinesToAdd: $polylinesToAdd, ' - 'polylineIdsToRemove: $polylineIdsToRemove, ' - 'polylinesToChange: $polylinesToChange}'; - } + Set get polylinesToChange => objectsToChange; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart index f182d43ce2d8..f9e979e0b49f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart @@ -10,26 +10,9 @@ import 'package:meta/meta.dart' show immutable, required; /// Uniquely identifies a [TileOverlay] among [GoogleMap] tile overlays. @immutable -class TileOverlayId { +class TileOverlayId extends MapsObjectId { /// Creates an immutable identifier for a [TileOverlay]. - TileOverlayId(this.value) : assert(value != null); - - /// The value of the [TileOverlayId]. - final String value; - - @override - bool operator ==(Object other) { - if (other.runtimeType != runtimeType) { - return false; - } - return other is TileOverlayId && other.value == value; - } - - @override - int get hashCode => value.hashCode; - - @override - String toString() => '${objectRuntimeType(this, 'TileOverlayId')}($value)'; + TileOverlayId(String value) : super(value); } /// A set of images which are displayed on top of the base map tiles. @@ -61,20 +44,23 @@ class TileOverlayId { /// At zoom level N, the x values of the tile coordinates range from 0 to 2N - 1 and increase from /// west to east and the y values range from 0 to 2N - 1 and increase from north to south. /// -class TileOverlay { +class TileOverlay implements MapsObject { /// Creates an immutable representation of a [TileOverlay] to draw on [GoogleMap]. const TileOverlay({ @required this.tileOverlayId, this.fadeIn = true, this.tileProvider, this.transparency = 0.0, - this.zIndex, + this.zIndex = 0, this.visible = true, this.tileSize = 256, }) : assert(transparency >= 0.0 && transparency <= 1.0); /// Uniquely identifies a [TileOverlay]. - final TileOverlayId tileOverlayId; + final TileOverlayId/*!*/ tileOverlayId; + + @override + TileOverlayId get mapsId => tileOverlayId; /// Whether the tiles should fade in. The default is true. final bool fadeIn; @@ -104,7 +90,6 @@ class TileOverlay { /// Creates a new [TileOverlay] object whose values are the same as this instance, /// unless overwritten by the specified parameters. TileOverlay copyWith({ - TileOverlayId tileOverlayId, bool fadeInParam, double transparencyParam, int zIndexParam, @@ -121,6 +106,8 @@ class TileOverlay { ); } + TileOverlay clone() => copyWith(); + /// Converts this object to JSON. Map toJson() { final Map json = {}; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart index 2910fc37d495..6fe9622fd438 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart @@ -2,121 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/foundation.dart' show objectRuntimeType, setEquals; -import 'dart:ui' show hashValues, hashList; - -import 'utils/tile_overlay.dart'; import 'types.dart'; /// Update specification for a set of [TileOverlay]s. -class TileOverlayUpdates { +class TileOverlayUpdates extends MapsObjectUpdates { /// Computes [TileOverlayUpdates] given previous and current [TileOverlay]s. - TileOverlayUpdates.from(Set previous, Set current) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - - final Map previousTileOverlays = - keyTileOverlayId(previous); - final Map currentTileOverlays = - keyTileOverlayId(current); - - final Set prevTileOverlayIds = - previousTileOverlays.keys.toSet(); - final Set currentTileOverlayIds = - currentTileOverlays.keys.toSet(); - - TileOverlay idToCurrentTileOverlay(TileOverlayId id) { - return currentTileOverlays[id]; - } - - _tileOverlayIdsToRemove = - prevTileOverlayIds.difference(currentTileOverlayIds); - - _tileOverlaysToAdd = currentTileOverlayIds - .difference(prevTileOverlayIds) - .map(idToCurrentTileOverlay) - .toSet(); - - // Returns `true` if [current] is not equals to previous one with the - // same id. - bool hasChanged(TileOverlay current) { - final TileOverlay previous = previousTileOverlays[current.tileOverlayId]; - return current != previous; - } - - _tileOverlaysToChange = currentTileOverlayIds - .intersection(prevTileOverlayIds) - .map(idToCurrentTileOverlay) - .where(hasChanged) - .toSet(); - } + TileOverlayUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'tileOverlay'); /// Set of TileOverlays to be added in this update. - Set get tileOverlaysToAdd { - return _tileOverlaysToAdd; - } - - Set _tileOverlaysToAdd; + Set get tileOverlaysToAdd => objectsToAdd; /// Set of TileOverlayIds to be removed in this update. - Set get tileOverlayIdsToRemove { - return _tileOverlayIdsToRemove; - } - - Set _tileOverlayIdsToRemove; + Set get tileOverlayIdsToRemove => objectIdsToRemove.cast(); /// Set of TileOverlays to be changed in this update. - Set get tileOverlaysToChange { - return _tileOverlaysToChange; - } - - Set _tileOverlaysToChange; - - /// Converts this object to JSON. - Map toJson() { - final Map updateMap = {}; - - void addIfNonNull(String fieldName, dynamic value) { - if (value != null) { - updateMap[fieldName] = value; - } - } - - addIfNonNull( - 'tileOverlaysToAdd', serializeTileOverlaySet(_tileOverlaysToAdd)); - addIfNonNull( - 'tileOverlaysToChange', serializeTileOverlaySet(_tileOverlaysToChange)); - addIfNonNull( - 'tileOverlayIdsToRemove', - _tileOverlayIdsToRemove - .map((TileOverlayId m) => m.value) - .toList()); - - return updateMap; - } - - @override - bool operator ==(Object other) { - if (other.runtimeType != runtimeType) { - return false; - } - return other is TileOverlayUpdates && - setEquals(_tileOverlaysToAdd, other._tileOverlaysToAdd) && - setEquals(_tileOverlayIdsToRemove, other._tileOverlayIdsToRemove) && - setEquals(_tileOverlaysToChange, other._tileOverlaysToChange); - } - - @override - int get hashCode => hashValues(hashList(_tileOverlaysToAdd), - hashList(_tileOverlayIdsToRemove), hashList(_tileOverlaysToChange)); - - @override - String toString() { - return '${objectRuntimeType(this, 'TileOverlayUpdates')}($_tileOverlaysToAdd, $_tileOverlayIdsToRemove, $_tileOverlaysToChange)'; - } + Set get tileOverlaysToChange => objectsToChange; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart index 3e2002f80ae3..9b7da87f2cb0 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart @@ -11,6 +11,8 @@ export 'circle_updates.dart'; export 'circle.dart'; export 'joint_type.dart'; export 'location.dart'; +export 'maps_object_updates.dart'; +export 'maps_object.dart'; export 'marker_updates.dart'; export 'marker.dart'; export 'pattern_item.dart'; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart index 6a132fe83561..1fb6e5188b50 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart @@ -3,20 +3,14 @@ // found in the LICENSE file. import '../types.dart'; +import 'maps_object.dart'; /// Converts an [Iterable] of Circles in a Map of CircleId -> Circle. Map keyByCircleId(Iterable circles) { - if (circles == null) { - return {}; - } - return Map.fromEntries(circles.map((Circle circle) => - MapEntry(circle.circleId, circle.clone()))); + return keyByMapsObjectId(circles); } /// Converts a Set of Circles into something serializable in JSON. -List> serializeCircleSet(Set/*!*/ circles) { - if (circles == null) { - return null; - } - return circles.map>((Circle p) => p.toJson()).toList(); +List> serializeCircleSet(Set circles) { + return serializeMapsObjectSet(circles); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart new file mode 100644 index 000000000000..e7a86b66a269 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart @@ -0,0 +1,25 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '../maps_object.dart'; + +/// Converts an [Iterable] of [MapsObject]s in a Map of [MapObjectId] -> [MapObject]. +Map, T> keyByMapsObjectId(Iterable objects) { + if (objects == null) { + return , T>{}; + } + return Map, T>.fromEntries(objects.map((T object) => + MapEntry, T>(object.mapsId, object.clone()))); +} + +/// Converts a Set of [MapsObject]s into something serializable in JSON. +List> serializeMapsObjectSet( + Set mapsObjects) { + if (mapsObjects == null) { + return null; + } + return mapsObjects + .map>((MapsObject p) => p.toJson()) + .toList(); +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart index 9f3450fcc0e6..c2a4cb8dcfd1 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart @@ -3,20 +3,14 @@ // found in the LICENSE file. import '../types.dart'; +import 'maps_object.dart'; /// Converts an [Iterable] of Markers in a Map of MarkerId -> Marker. Map keyByMarkerId(Iterable markers) { - if (markers == null) { - return {}; - } - return Map.fromEntries(markers.map((Marker marker) => - MapEntry(marker.markerId, marker.clone()))); + return keyByMapsObjectId(markers); } /// Converts a Set of Markers into something serializable in JSON. -List> serializeMarkerSet(Set/*!*/ markers) { - if (markers == null) { - return null; - } - return markers.map>((Marker m) => m.toJson()).toList(); +List> serializeMarkerSet(Set markers) { + return serializeMapsObjectSet(markers); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart index 7d4a5b7188df..61ea3a846b7d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart @@ -3,20 +3,14 @@ // found in the LICENSE file. import '../types.dart'; +import 'maps_object.dart'; /// Converts an [Iterable] of Polygons in a Map of PolygonId -> Polygon. Map keyByPolygonId(Iterable polygons) { - if (polygons == null) { - return {}; - } - return Map.fromEntries(polygons.map((Polygon polygon) => - MapEntry(polygon.polygonId, polygon.clone()))); + return keyByMapsObjectId(polygons); } /// Converts a Set of Polygons into something serializable in JSON. -List> serializePolygonSet(Set/*!*/ polygons) { - if (polygons == null) { - return null; - } - return polygons.map>((Polygon p) => p.toJson()).toList(); +List> serializePolygonSet(Set polygons) { + return serializeMapsObjectSet(polygons); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart index 8d1cd74ec284..eea4f1caa97b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart @@ -3,23 +3,14 @@ // found in the LICENSE file. import '../types.dart'; +import 'maps_object.dart'; /// Converts an [Iterable] of Polylines in a Map of PolylineId -> Polyline. Map keyByPolylineId(Iterable polylines) { - if (polylines == null) { - return {}; - } - return Map.fromEntries(polylines.map( - (Polyline polyline) => MapEntry( - polyline.polylineId, polyline.clone()))); + return keyByMapsObjectId(polylines); } /// Converts a Set of Polylines into something serializable in JSON. -List> serializePolylineSet(Set/*!*/ polylines) { - if (polylines == null) { - return null; - } - return polylines - .map>((Polyline p) => p.toJson()) - .toList(); +List> serializePolylineSet(Set polylines) { + return serializeMapsObjectSet(polylines); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart index 0c817fd2150c..02c1cb53c60b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart @@ -1,23 +1,18 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + import '../types.dart'; +import 'maps_object.dart'; /// Converts an [Iterable] of TileOverlay in a Map of TileOverlayId -> TileOverlay. Map keyTileOverlayId( Iterable/*!*/ tileOverlays) { - if (tileOverlays == null) { - return {}; - } - return Map.fromEntries(tileOverlays.map( - (TileOverlay tileOverlay) => MapEntry( - tileOverlay.tileOverlayId, tileOverlay))); + return keyByMapsObjectId(tileOverlays); } /// Converts a Set of TileOverlays into something serializable in JSON. List> serializeTileOverlaySet( - Set/*!*/ tileOverlays) { - if (tileOverlays == null) { - return null; - } - return tileOverlays - .map>((TileOverlay p) => p.toJson()) - .toList(); + Set tileOverlays) { + return serializeMapsObjectSet(tileOverlays); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_test.dart index bb0621d23ae3..c6254138c4d3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_test.dart @@ -20,7 +20,7 @@ void main() { test('toString', () async { final TileOverlayId id1 = TileOverlayId('1'); - expect(id1.toString(), 'TileOverlayId(1)'); + expect(id1.toString(), 'TileOverlayId{value: 1}'); }); }); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_updates_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_updates_test.dart index 980a203f709e..1d529088e460 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_updates_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_updates_test.dart @@ -117,9 +117,9 @@ void main() { TileOverlayUpdates.from(previous, current); expect( updates.toString(), - 'TileOverlayUpdates(${updates.tileOverlaysToAdd}, ' - '${updates.tileOverlayIdsToRemove}, ' - '${updates.tileOverlaysToChange})'); + 'TileOverlayUpdates{add: ${updates.tileOverlaysToAdd}, ' + 'remove: ${updates.tileOverlayIdsToRemove}, ' + 'change: ${updates.tileOverlaysToChange}}'); }); }); } From fe2ffddf21e9464c6ce47050c35fa245e124ebd3 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 9 Feb 2021 14:25:27 -0500 Subject: [PATCH 03/14] Test for extracted base class --- .../lib/src/types/utils/circle.dart | 4 +- .../lib/src/types/utils/marker.dart | 4 +- .../lib/src/types/utils/polygon.dart | 4 +- .../lib/src/types/utils/polyline.dart | 4 +- .../lib/src/types/utils/tile_overlay.dart | 4 +- .../test/types/maps_object_test.dart | 60 +++++++ .../test/types/maps_object_updates_test.dart | 160 ++++++++++++++++++ .../test/types/test_maps_object.dart | 46 +++++ 8 files changed, 276 insertions(+), 10 deletions(-) create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_updates_test.dart create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/test_maps_object.dart diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart index 1fb6e5188b50..9fc379fd39cd 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart @@ -6,8 +6,8 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Circles in a Map of CircleId -> Circle. -Map keyByCircleId(Iterable circles) { - return keyByMapsObjectId(circles); +Map keyByCircleId(Iterable/*?*/ circles) { + return keyByMapsObjectId(circles).cast(); } /// Converts a Set of Circles into something serializable in JSON. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart index c2a4cb8dcfd1..b9b64cc7ce7d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart @@ -6,8 +6,8 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Markers in a Map of MarkerId -> Marker. -Map keyByMarkerId(Iterable markers) { - return keyByMapsObjectId(markers); +Map keyByMarkerId(Iterable/*?*/ markers) { + return keyByMapsObjectId(markers).cast(); } /// Converts a Set of Markers into something serializable in JSON. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart index 61ea3a846b7d..40cdd92ba21d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart @@ -6,8 +6,8 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Polygons in a Map of PolygonId -> Polygon. -Map keyByPolygonId(Iterable polygons) { - return keyByMapsObjectId(polygons); +Map keyByPolygonId(Iterable/*?*/ polygons) { + return keyByMapsObjectId(polygons).cast(); } /// Converts a Set of Polygons into something serializable in JSON. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart index eea4f1caa97b..5bab00470fff 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart @@ -6,8 +6,8 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Polylines in a Map of PolylineId -> Polyline. -Map keyByPolylineId(Iterable polylines) { - return keyByMapsObjectId(polylines); +Map keyByPolylineId(Iterable/*?*/ polylines) { + return keyByMapsObjectId(polylines).cast(); } /// Converts a Set of Polylines into something serializable in JSON. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart index 02c1cb53c60b..0f332140c23c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart @@ -7,8 +7,8 @@ import 'maps_object.dart'; /// Converts an [Iterable] of TileOverlay in a Map of TileOverlayId -> TileOverlay. Map keyTileOverlayId( - Iterable/*!*/ tileOverlays) { - return keyByMapsObjectId(tileOverlays); + Iterable/*?*/ tileOverlays) { + return keyByMapsObjectId(tileOverlays).cast(); } /// Converts a Set of TileOverlays into something serializable in JSON. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart new file mode 100644 index 000000000000..bba924c3225e --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart @@ -0,0 +1,60 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/utils/maps_object.dart'; + +import 'test_maps_object.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('keyByMapsObjectId tests', () { + test('normal', () async { + final MapsObjectId id1 = + MapsObjectId('1'); + final MapsObjectId id2 = + MapsObjectId('2'); + final MapsObjectId id3 = + MapsObjectId('3'); + final TestMapsObject object1 = TestMapsObject(id1); + final TestMapsObject object2 = TestMapsObject(id2, data: 2); + final TestMapsObject object3 = TestMapsObject(id3); + expect( + keyByMapsObjectId({object1, object2, object3}), + , TestMapsObject>{ + id1: object1, + id2: object2, + id3: object3, + }); + }); + + test('null', () async { + expect(keyByMapsObjectId(null), + , TestMapsObject>{}); + }); + }); + + group('serializeMapsObjectSet tests', () { + test('normal', () async { + final MapsObjectId id1 = + MapsObjectId('1'); + final MapsObjectId id2 = + MapsObjectId('2'); + final MapsObjectId id3 = + MapsObjectId('3'); + final TestMapsObject object1 = TestMapsObject(id1); + final TestMapsObject object2 = TestMapsObject(id2, data: 2); + final TestMapsObject object3 = TestMapsObject(id3); + expect( + serializeMapsObjectSet({object1, object2, object3}), + >[{'id': '1'}, {'id': '2'}, {'id': '3'}]); + }); + + test('null', () async { + expect(serializeMapsObjectSet(null), isNull); + }); + }); +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_updates_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_updates_test.dart new file mode 100644 index 000000000000..82039037bc3b --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_updates_test.dart @@ -0,0 +1,160 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show hashValues, hashList; + +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/utils/maps_object.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/maps_object_updates.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/maps_object.dart'; + +import 'test_maps_object.dart'; + +class TestMapsObjectUpdate extends MapsObjectUpdates { + TestMapsObjectUpdate.from( + Set previous, Set current) + : super.from(previous, current, objectName: 'testObject'); +} + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('tile overlay updates tests', () { + test('Correctly set toRemove, toAdd and toChange', () async { + final TestMapsObject to1 = + TestMapsObject(MapsObjectId('id1')); + final TestMapsObject to2 = + TestMapsObject(MapsObjectId('id2')); + final TestMapsObject to3 = + TestMapsObject(MapsObjectId('id3')); + final TestMapsObject to3Changed = + TestMapsObject(MapsObjectId('id3'), data: 2); + final TestMapsObject to4 = + TestMapsObject(MapsObjectId('id4')); + final Set previous = + Set.from([to1, to2, to3]); + final Set current = + Set.from([to2, to3Changed, to4]); + final TestMapsObjectUpdate updates = + TestMapsObjectUpdate.from(previous, current); + + final Set> toRemove = Set.from( + >[MapsObjectId('id1')]); + expect(updates.objectIdsToRemove, toRemove); + + final Set toAdd = Set.from([to4]); + expect(updates.objectsToAdd, toAdd); + + final Set toChange = + Set.from([to3Changed]); + expect(updates.objectsToChange, toChange); + }); + + test('toJson', () async { + final TestMapsObject to1 = + TestMapsObject(MapsObjectId('id1')); + final TestMapsObject to2 = + TestMapsObject(MapsObjectId('id2')); + final TestMapsObject to3 = + TestMapsObject(MapsObjectId('id3')); + final TestMapsObject to3Changed = + TestMapsObject(MapsObjectId('id3'), data: 2); + final TestMapsObject to4 = + TestMapsObject(MapsObjectId('id4')); + final Set previous = + Set.from([to1, to2, to3]); + final Set current = + Set.from([to2, to3Changed, to4]); + final TestMapsObjectUpdate updates = + TestMapsObjectUpdate.from(previous, current); + + final Map json = updates.toJson(); + expect(json, { + 'testObjectsToAdd': serializeMapsObjectSet(updates.objectsToAdd), + 'testObjectsToChange': serializeMapsObjectSet(updates.objectsToChange), + 'testObjectIdsToRemove': updates.objectIdsToRemove + .map((MapsObjectId m) => m.value) + .toList() + }); + }); + + test('equality', () async { + final TestMapsObject to1 = + TestMapsObject(MapsObjectId('id1')); + final TestMapsObject to2 = + TestMapsObject(MapsObjectId('id2')); + final TestMapsObject to3 = + TestMapsObject(MapsObjectId('id3')); + final TestMapsObject to3Changed = + TestMapsObject(MapsObjectId('id3'), data: 2); + final TestMapsObject to4 = + TestMapsObject(MapsObjectId('id4')); + final Set previous = + Set.from([to1, to2, to3]); + final Set current1 = + Set.from([to2, to3Changed, to4]); + final Set current2 = + Set.from([to2, to3Changed, to4]); + final Set current3 = Set.from([to2, to4]); + final TestMapsObjectUpdate updates1 = + TestMapsObjectUpdate.from(previous, current1); + final TestMapsObjectUpdate updates2 = + TestMapsObjectUpdate.from(previous, current2); + final TestMapsObjectUpdate updates3 = + TestMapsObjectUpdate.from(previous, current3); + expect(updates1, updates2); + expect(updates1, isNot(updates3)); + }); + + test('hashCode', () async { + final TestMapsObject to1 = + TestMapsObject(MapsObjectId('id1')); + final TestMapsObject to2 = + TestMapsObject(MapsObjectId('id2')); + final TestMapsObject to3 = + TestMapsObject(MapsObjectId('id3')); + final TestMapsObject to3Changed = + TestMapsObject(MapsObjectId('id3'), data: 2); + final TestMapsObject to4 = + TestMapsObject(MapsObjectId('id4')); + final Set previous = + Set.from([to1, to2, to3]); + final Set current = + Set.from([to2, to3Changed, to4]); + final TestMapsObjectUpdate updates = + TestMapsObjectUpdate.from(previous, current); + expect( + updates.hashCode, + hashValues( + hashList(updates.objectsToAdd), + hashList(updates.objectIdsToRemove), + hashList(updates.objectsToChange))); + }); + + test('toString', () async { + final TestMapsObject to1 = + TestMapsObject(MapsObjectId('id1')); + final TestMapsObject to2 = + TestMapsObject(MapsObjectId('id2')); + final TestMapsObject to3 = + TestMapsObject(MapsObjectId('id3')); + final TestMapsObject to3Changed = + TestMapsObject(MapsObjectId('id3'), data: 2); + final TestMapsObject to4 = + TestMapsObject(MapsObjectId('id4')); + final Set previous = + Set.from([to1, to2, to3]); + final Set current = + Set.from([to2, to3Changed, to4]); + final TestMapsObjectUpdate updates = + TestMapsObjectUpdate.from(previous, current); + expect( + updates.toString(), + 'TestMapsObjectUpdate{add: ${updates.objectsToAdd}, ' + 'remove: ${updates.objectIdsToRemove}, ' + 'change: ${updates.objectsToChange}}'); + }); + }); +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/test_maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/test_maps_object.dart new file mode 100644 index 000000000000..896631e94605 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/test_maps_object.dart @@ -0,0 +1,46 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui' show hashValues; +import 'package:flutter/rendering.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/maps_object_updates.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/maps_object.dart'; + +/// A trivial TestMapsObject implementation for testing updates with. +class TestMapsObject implements MapsObject { + TestMapsObject(this.mapsId, {this.data = 1}); + + final MapsObjectId mapsId; + + final int data; + + @override + TestMapsObject clone() { + return TestMapsObject(mapsId, data: data); + } + + @override + dynamic toJson() { + return {'id': mapsId.value}; + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is TestMapsObject && + mapsId == other.mapsId && + data == other.data; + } + + @override + int get hashCode => hashValues(mapsId, data); +} + +class TestMapsObjectUpdate extends MapsObjectUpdates { + TestMapsObjectUpdate.from( + Set previous, Set current) + : super.from(previous, current, objectName: 'testObject'); +} From 0a703d7a5c31a3eede682b7bf2738384f626f39b Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 9 Feb 2021 15:55:26 -0500 Subject: [PATCH 04/14] More pre-migration adjustment --- .../method_channel_google_maps_flutter.dart | 39 ++++++++++++++----- .../google_maps_flutter_platform.dart | 6 +-- .../lib/src/types/circle_updates.dart | 6 +-- .../lib/src/types/maps_object_updates.dart | 8 ++-- .../lib/src/types/screen_coordinate.dart | 6 +-- .../lib/src/types/tile.dart | 4 +- .../lib/src/types/utils/circle.dart | 2 +- .../lib/src/types/utils/marker.dart | 2 +- .../lib/src/types/utils/polygon.dart | 2 +- .../lib/src/types/utils/tile_overlay.dart | 4 +- 10 files changed, 50 insertions(+), 29 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index 6bc3c0cedb29..6328a0e5862d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -15,6 +15,22 @@ import 'package:stream_transform/stream_transform.dart'; import '../types/tile_overlay_updates.dart'; import '../types/utils/tile_overlay.dart'; +/// Error thrown when an unknown map ID is provided to a method channel API. +class UnknownMapIDError extends Error { + /// Message describing the assertion error. + final Object message; + + /// Creates an assertion error with the provided [message]. + UnknownMapIDError([this.message]); + + String toString() { + if (message != null) { + return "Unknown map ID: ${Error.safeToString(message)}"; + } + return "Unknown map ID"; + } +} + /// An implementation of [GoogleMapsFlutterPlatform] that uses [MethodChannel] to communicate with the native code. /// /// The `google_maps_flutter` plugin code itself never talks to the native code directly. It delegates @@ -32,7 +48,11 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// Accesses the MethodChannel associated to the passed mapId. MethodChannel channel(int mapId) { - return _channels[mapId]; + MethodChannel channel = _channels[mapId]; + if (channel == null) { + throw UnknownMapIDError(); + } + return channel; } // Keep a collection of mapId to a map of TileOverlays. @@ -190,16 +210,17 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { )); break; case 'tileOverlay#getTile': - final Map tileOverlaysForThisMap = + final Map/*?*/ tileOverlaysForThisMap = _tileOverlays[mapId]; final String tileOverlayId = call.arguments['tileOverlayId']; + /* XXX fix this*/ final TileOverlay tileOverlay = - tileOverlaysForThisMap[TileOverlayId(tileOverlayId)]; - Tile tile; - if (tileOverlay == null || tileOverlay.tileProvider == null) { + tileOverlaysForThisMap/*?*/[TileOverlayId(tileOverlayId)]; + TileProvider tileProvider = tileOverlay?.tileProvider; + if (tileProvider == null) { return TileProvider.noTile.toJson(); } - tile = await tileOverlay.tileProvider.getTile( + final Tile tile = await tileProvider.getTile( call.arguments['x'], call.arguments['y'], call.arguments['zoom'], @@ -312,7 +333,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// If `newTileOverlays` is null, all the [TileOverlays] are removed for the Map with `mapId`. @override Future updateTileOverlays({ - Set newTileOverlays, + @required Set newTileOverlays, @required int mapId, }) { final Map currentTileOverlays = @@ -491,7 +512,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// * [showMarkerInfoWindow] to show the Info Window. /// * [hideMarkerInfoWindow] to hide the Info Window. @override - Future isMarkerInfoWindowShown( + Future isMarkerInfoWindowShown( MarkerId markerId, { @required int mapId, }) { @@ -502,7 +523,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// Returns the current zoom level of the map @override - Future getZoomLevel({ + Future getZoomLevel({ @required int mapId, }) { return channel(mapId).invokeMethod('map#getZoomLevel'); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart index b9d3fecc0d0a..441e4face49b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart @@ -122,7 +122,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// /// The returned [Future] completes after listeners have been notified. Future updateTileOverlays({ - Set newTileOverlays, + @required Set newTileOverlays, @required int mapId, }) { throw UnimplementedError('updateTileOverlays() has not been implemented.'); @@ -252,7 +252,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// * See also: /// * [showMarkerInfoWindow] to show the Info Window. /// * [hideMarkerInfoWindow] to hide the Info Window. - Future isMarkerInfoWindowShown( + Future isMarkerInfoWindowShown( MarkerId markerId, { @required int mapId, }) { @@ -260,7 +260,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { } /// Returns the current zoom level of the map - Future getZoomLevel({ + Future getZoomLevel({ @required int mapId, }) { throw UnimplementedError('getZoomLevel() has not been implemented.'); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart index 470db36b96ac..7c8afbec5bd9 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart @@ -13,11 +13,11 @@ class CircleUpdates extends MapsObjectUpdates { CircleUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'circle'); /// Set of Circles to be added in this update. - Set get circlesToAdd => objectsToAdd; + Set get circlesToAdd => objectsToAdd; /// Set of CircleIds to be removed in this update. - Set/*?*/ get circleIdsToRemove => objectIdsToRemove.cast(); + Set get circleIdsToRemove => objectIdsToRemove.cast(); /// Set of Circles to be changed in this update. - Set get circlesToChange => objectsToChange; + Set get circlesToChange => objectsToChange; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart index 16a655e079b9..ac32cc53d68c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart @@ -40,7 +40,7 @@ class MapsObjectUpdates { /// /// It is a programming error to call this with an ID that is not guaranteed /// to be in [currentObjects]. - T _idToCurrentObject(MapsObjectId id) { + T/*!*/ _idToCurrentObject(MapsObjectId id) { return currentObjects[id]; } @@ -73,21 +73,21 @@ class MapsObjectUpdates { return _objectsToAdd; } - Set _objectsToAdd; + /*late*/ Set _objectsToAdd; /// Set of objects to be removed in this update. Set> get objectIdsToRemove { return _objectIdsToRemove; } - Set> _objectIdsToRemove; + /*late*/ Set> _objectIdsToRemove; /// Set of objects to be changed in this update. Set get objectsToChange { return _objectsToChange; } - Set _objectsToChange; + /*late*/ Set _objectsToChange; /// Converts this object to JSON. Map toJson() { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart index 965db7969bc2..f9f34ea31837 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart @@ -20,14 +20,14 @@ class ScreenCoordinate { }); /// Represents the number of pixels from the left of the [GoogleMap]. - final int x; + final int/*!*/ x; /// Represents the number of pixels from the top of the [GoogleMap]. - final int y; + final int/*!*/ y; /// Converts this object to something serializable in JSON. dynamic toJson() { - return { + return { "x": x, "y": y, }; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart index a270ef6cf38f..6c29f076bb0b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart @@ -12,10 +12,10 @@ class Tile { const Tile(this.width, this.height, this.data); /// The width of the image encoded by data in logical pixels. - final int width; + final int/*!*/ width; /// The height of the image encoded by data in logical pixels. - final int height; + final int/*!*/ height; /// A byte array containing the image data. /// diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart index 9fc379fd39cd..6b875890ec7c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart @@ -11,6 +11,6 @@ Map keyByCircleId(Iterable/*?*/ circles) { } /// Converts a Set of Circles into something serializable in JSON. -List> serializeCircleSet(Set circles) { +List> serializeCircleSet(Set circles) { return serializeMapsObjectSet(circles); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart index b9b64cc7ce7d..a95b60b513db 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart @@ -11,6 +11,6 @@ Map keyByMarkerId(Iterable/*?*/ markers) { } /// Converts a Set of Markers into something serializable in JSON. -List> serializeMarkerSet(Set markers) { +List> serializeMarkerSet(Set markers) { return serializeMapsObjectSet(markers); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart index 40cdd92ba21d..eb8b378e9361 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart @@ -11,6 +11,6 @@ Map keyByPolygonId(Iterable/*?*/ polygons) { } /// Converts a Set of Polygons into something serializable in JSON. -List> serializePolygonSet(Set polygons) { +List> serializePolygonSet(Set polygons) { return serializeMapsObjectSet(polygons); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart index 0f332140c23c..ab0fd601a7b5 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart @@ -6,13 +6,13 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of TileOverlay in a Map of TileOverlayId -> TileOverlay. -Map keyTileOverlayId( +Map keyTileOverlayId( Iterable/*?*/ tileOverlays) { return keyByMapsObjectId(tileOverlays).cast(); } /// Converts a Set of TileOverlays into something serializable in JSON. List> serializeTileOverlaySet( - Set tileOverlays) { + Set tileOverlays) { return serializeMapsObjectSet(tileOverlays); } From b3f8de03175ae137f6886478fa5d582c58b82bee Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 10 Feb 2021 10:04:22 -0500 Subject: [PATCH 05/14] Initial tool migration plus trivial cleanup --- .../lib/src/events/map_event.dart | 10 +- .../method_channel_google_maps_flutter.dart | 123 +++++++++--------- .../google_maps_flutter_platform.dart | 68 +++++----- .../lib/src/types/bitmap.dart | 20 +-- .../lib/src/types/camera.dart | 10 +- .../lib/src/types/circle.dart | 28 ++-- .../lib/src/types/location.dart | 10 +- .../lib/src/types/maps_object.dart | 2 +- .../lib/src/types/maps_object_updates.dart | 19 ++- .../lib/src/types/marker.dart | 62 ++++----- .../lib/src/types/polygon.dart | 30 ++--- .../lib/src/types/polyline.dart | 40 +++--- .../lib/src/types/screen_coordinate.dart | 12 +- .../lib/src/types/tile.dart | 8 +- .../lib/src/types/tile_overlay.dart | 20 +-- .../lib/src/types/tile_overlay_updates.dart | 2 +- .../lib/src/types/tile_provider.dart | 2 +- .../lib/src/types/ui.dart | 6 +- .../lib/src/types/utils/circle.dart | 4 +- .../lib/src/types/utils/maps_object.dart | 8 +- .../lib/src/types/utils/marker.dart | 4 +- .../lib/src/types/utils/polygon.dart | 4 +- .../lib/src/types/utils/polyline.dart | 4 +- .../lib/src/types/utils/tile_overlay.dart | 4 +- .../pubspec.yaml | 2 +- .../test/types/tile_test.dart | 8 +- 26 files changed, 247 insertions(+), 263 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart index 10eb74187460..c462b4b182e2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/events/map_event.dart @@ -51,7 +51,7 @@ class MapEvent { /// A `MapEvent` associated to a `position`. class _PositionedMapEvent extends MapEvent { /// The position where this event happened. - final LatLng/*!*/ position; + final LatLng position; /// Build a Positioned MapEvent, that relates a mapId and a position with a value. /// @@ -73,11 +73,11 @@ class CameraMoveStartedEvent extends MapEvent { } /// An event fired while the Camera of a [mapId] moves. -class CameraMoveEvent extends MapEvent { +class CameraMoveEvent extends MapEvent { /// Build a CameraMove Event triggered from the map represented by `mapId`. /// /// The `value` of this event is a [CameraPosition] object with the current position of the Camera. - CameraMoveEvent(int mapId, CameraPosition/*!*/ position) : super(mapId, position); + CameraMoveEvent(int mapId, CameraPosition position) : super(mapId, position); } /// An event fired when the Camera of a [mapId] becomes idle. @@ -141,7 +141,7 @@ class MapTapEvent extends _PositionedMapEvent { /// Build an MapTap Event triggered from the map represented by `mapId`. /// /// The `position` of this event is the LatLng where the Map was tapped. - MapTapEvent(int mapId, LatLng/*!*/ position) : super(mapId, position, null); + MapTapEvent(int mapId, LatLng position) : super(mapId, position, null); } /// An event fired when a Map is long pressed. @@ -149,5 +149,5 @@ class MapLongPressEvent extends _PositionedMapEvent { /// Build an MapTap Event triggered from the map represented by `mapId`. /// /// The `position` of this event is the LatLng where the Map was long pressed. - MapLongPressEvent(int mapId, LatLng/*!*/ position) : super(mapId, position, null); + MapLongPressEvent(int mapId, LatLng position) : super(mapId, position, null); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index 6328a0e5862d..63b3f470df63 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -18,7 +18,7 @@ import '../types/utils/tile_overlay.dart'; /// Error thrown when an unknown map ID is provided to a method channel API. class UnknownMapIDError extends Error { /// Message describing the assertion error. - final Object message; + final Object? message; /// Creates an assertion error with the provided [message]. UnknownMapIDError([this.message]); @@ -44,11 +44,11 @@ class UnknownMapIDError extends Error { class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { // Keep a collection of id -> channel // Every method call passes the int mapId - final Map _channels = {}; + final Map _channels = {}; /// Accesses the MethodChannel associated to the passed mapId. MethodChannel channel(int mapId) { - MethodChannel channel = _channels[mapId]; + MethodChannel? channel = _channels[mapId]; if (channel == null) { throw UnknownMapIDError(); } @@ -63,7 +63,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// This method is called when the plugin is first initialized. @override Future init(int mapId) { - MethodChannel channel = _channels[mapId]; + MethodChannel? channel = _channels[mapId]; if (channel == null) { channel = MethodChannel('plugins.flutter.io/google_maps_$mapId'); channel.setMethodCallHandler( @@ -75,7 +75,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// Dispose of the native resources. @override - void dispose({int mapId}) { + void dispose({int? mapId}) { // Noop! } @@ -92,57 +92,57 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { _mapEventStreamController.stream.where((event) => event.mapId == mapId); @override - Stream onCameraMoveStarted({@required int mapId}) { + Stream onCameraMoveStarted({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onCameraMove({@required int mapId}) { + Stream onCameraMove({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onCameraIdle({@required int mapId}) { + Stream onCameraIdle({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onMarkerTap({@required int mapId}) { + Stream onMarkerTap({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onInfoWindowTap({@required int mapId}) { + Stream onInfoWindowTap({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onMarkerDragEnd({@required int mapId}) { + Stream onMarkerDragEnd({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onPolylineTap({@required int mapId}) { + Stream onPolylineTap({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onPolygonTap({@required int mapId}) { + Stream onPolygonTap({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onCircleTap({@required int mapId}) { + Stream onCircleTap({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onTap({@required int mapId}) { + Stream onTap({required int mapId}) { return _events(mapId).whereType(); } @override - Stream onLongPress({@required int mapId}) { + Stream onLongPress({required int mapId}) { return _events(mapId).whereType(); } @@ -154,7 +154,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { case 'camera#onMove': _mapEventStreamController.add(CameraMoveEvent( mapId, - CameraPosition.fromMap(call.arguments['position']), + CameraPosition.fromMap(call.arguments['position'])!, )); break; case 'camera#onIdle': @@ -169,7 +169,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { case 'marker#onDragEnd': _mapEventStreamController.add(MarkerDragEndEvent( mapId, - LatLng.fromJson(call.arguments['position']), + LatLng.fromJson(call.arguments['position'])!, MarkerId(call.arguments['markerId']), )); break; @@ -200,23 +200,22 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { case 'map#onTap': _mapEventStreamController.add(MapTapEvent( mapId, - LatLng.fromJson(call.arguments['position']), + LatLng.fromJson(call.arguments['position'])!, )); break; case 'map#onLongPress': _mapEventStreamController.add(MapLongPressEvent( mapId, - LatLng.fromJson(call.arguments['position']), + LatLng.fromJson(call.arguments['position'])!, )); break; case 'tileOverlay#getTile': - final Map/*?*/ tileOverlaysForThisMap = + final Map? tileOverlaysForThisMap = _tileOverlays[mapId]; final String tileOverlayId = call.arguments['tileOverlayId']; - /* XXX fix this*/ - final TileOverlay tileOverlay = - tileOverlaysForThisMap/*?*/[TileOverlayId(tileOverlayId)]; - TileProvider tileProvider = tileOverlay?.tileProvider; + final TileOverlay? tileOverlay = + tileOverlaysForThisMap?[TileOverlayId(tileOverlayId)]; + TileProvider? tileProvider = tileOverlay?.tileProvider; if (tileProvider == null) { return TileProvider.noTile.toJson(); } @@ -240,7 +239,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future updateMapOptions( Map optionsUpdate, { - @required int mapId, + required int mapId, }) { assert(optionsUpdate != null); return channel(mapId).invokeMethod( @@ -260,7 +259,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future updateMarkers( MarkerUpdates markerUpdates, { - @required int mapId, + required int mapId, }) { assert(markerUpdates != null); return channel(mapId).invokeMethod( @@ -278,7 +277,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future updatePolygons( PolygonUpdates polygonUpdates, { - @required int mapId, + required int mapId, }) { assert(polygonUpdates != null); return channel(mapId).invokeMethod( @@ -296,7 +295,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future updatePolylines( PolylineUpdates polylineUpdates, { - @required int mapId, + required int mapId, }) { assert(polylineUpdates != null); return channel(mapId).invokeMethod( @@ -314,7 +313,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future updateCircles( CircleUpdates circleUpdates, { - @required int mapId, + required int mapId, }) { assert(circleUpdates != null); return channel(mapId).invokeMethod( @@ -333,12 +332,12 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// If `newTileOverlays` is null, all the [TileOverlays] are removed for the Map with `mapId`. @override Future updateTileOverlays({ - @required Set newTileOverlays, - @required int mapId, + required Set newTileOverlays, + required int mapId, }) { - final Map currentTileOverlays = + final Map? currentTileOverlays = _tileOverlays[mapId]; - Set previousSet = + Set? previousSet = currentTileOverlays != null ? currentTileOverlays.values.toSet() : null; final TileOverlayUpdates updates = TileOverlayUpdates.from(previousSet, newTileOverlays); @@ -359,7 +358,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future clearTileCache( TileOverlayId tileOverlayId, { - @required int mapId, + required int mapId, }) { return channel(mapId) .invokeMethod('tileOverlays#clearTileCache', { @@ -374,7 +373,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future animateCamera( CameraUpdate cameraUpdate, { - @required int mapId, + required int mapId, }) { return channel(mapId) .invokeMethod('camera#animate', { @@ -389,7 +388,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future moveCamera( CameraUpdate cameraUpdate, { - @required int mapId, + required int mapId, }) { return channel(mapId).invokeMethod('camera#move', { 'cameraUpdate': cameraUpdate.toJson(), @@ -412,10 +411,10 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future setMapStyle( String mapStyle, { - @required int mapId, + required int mapId, }) async { - final List successAndError = await channel(mapId) - .invokeMethod>('map#setStyle', mapStyle); + final List successAndError = await (channel(mapId) + .invokeMethod>('map#setStyle', mapStyle) as FutureOr>); final bool success = successAndError[0]; if (!success) { throw MapStyleException(successAndError[1]); @@ -425,12 +424,12 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// Return the region that is visible in a map. @override Future getVisibleRegion({ - @required int mapId, + required int mapId, }) async { - final Map latLngBounds = await channel(mapId) - .invokeMapMethod('map#getVisibleRegion'); - final LatLng southwest = LatLng.fromJson(latLngBounds['southwest']); - final LatLng northeast = LatLng.fromJson(latLngBounds['northeast']); + final Map latLngBounds = await (channel(mapId) + .invokeMapMethod('map#getVisibleRegion') as FutureOr>); + final LatLng southwest = LatLng.fromJson(latLngBounds['southwest'])!; + final LatLng northeast = LatLng.fromJson(latLngBounds['northeast'])!; return LatLngBounds(northeast: northeast, southwest: southwest); } @@ -443,13 +442,13 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future getScreenCoordinate( LatLng latLng, { - @required int mapId, + required int mapId, }) async { - final Map point = await channel(mapId) + final Map point = await (channel(mapId) .invokeMapMethod( - 'map#getScreenCoordinate', latLng.toJson()); + 'map#getScreenCoordinate', latLng.toJson()) as FutureOr>); - return ScreenCoordinate(x: point['x'], y: point['y']); + return ScreenCoordinate(x: point['x']!, y: point['y']!); } /// Returns [LatLng] corresponding to the [ScreenCoordinate] in the current map view. @@ -459,11 +458,11 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future getLatLng( ScreenCoordinate screenCoordinate, { - @required int mapId, + required int mapId, }) async { - final List latLng = await channel(mapId) + final List latLng = await (channel(mapId) .invokeMethod>( - 'map#getLatLng', screenCoordinate.toJson()); + 'map#getLatLng', screenCoordinate.toJson()) as FutureOr>); return LatLng(latLng[0], latLng[1]); } @@ -478,7 +477,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future showMarkerInfoWindow( MarkerId markerId, { - @required int mapId, + required int mapId, }) { assert(markerId != null); return channel(mapId).invokeMethod( @@ -496,7 +495,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future hideMarkerInfoWindow( MarkerId markerId, { - @required int mapId, + required int mapId, }) { assert(markerId != null); return channel(mapId).invokeMethod( @@ -512,27 +511,27 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// * [showMarkerInfoWindow] to show the Info Window. /// * [hideMarkerInfoWindow] to hide the Info Window. @override - Future isMarkerInfoWindowShown( + Future isMarkerInfoWindowShown( MarkerId markerId, { - @required int mapId, + required int mapId, }) { assert(markerId != null); return channel(mapId).invokeMethod('markers#isInfoWindowShown', - {'markerId': markerId.value}); + {'markerId': markerId.value}) as Future; } /// Returns the current zoom level of the map @override - Future getZoomLevel({ - @required int mapId, + Future getZoomLevel({ + required int mapId, }) { - return channel(mapId).invokeMethod('map#getZoomLevel'); + return channel(mapId).invokeMethod('map#getZoomLevel') as Future; } /// Returns the image bytes of the map @override - Future takeSnapshot({ - @required int mapId, + Future takeSnapshot({ + required int mapId, }) { return channel(mapId).invokeMethod('map#takeSnapshot'); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart index 441e4face49b..92bee870ebe3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart @@ -58,7 +58,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// The returned [Future] completes after listeners have been notified. Future updateMapOptions( Map optionsUpdate, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('updateMapOptions() has not been implemented.'); } @@ -71,7 +71,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// The returned [Future] completes after listeners have been notified. Future updateMarkers( MarkerUpdates markerUpdates, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('updateMarkers() has not been implemented.'); } @@ -84,7 +84,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// The returned [Future] completes after listeners have been notified. Future updatePolygons( PolygonUpdates polygonUpdates, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('updatePolygons() has not been implemented.'); } @@ -97,7 +97,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// The returned [Future] completes after listeners have been notified. Future updatePolylines( PolylineUpdates polylineUpdates, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('updatePolylines() has not been implemented.'); } @@ -110,7 +110,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// The returned [Future] completes after listeners have been notified. Future updateCircles( CircleUpdates circleUpdates, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('updateCircles() has not been implemented.'); } @@ -122,8 +122,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// /// The returned [Future] completes after listeners have been notified. Future updateTileOverlays({ - @required Set newTileOverlays, - @required int mapId, + required Set newTileOverlays, + required int mapId, }) { throw UnimplementedError('updateTileOverlays() has not been implemented.'); } @@ -137,7 +137,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// should implement an on-disk cache. Future clearTileCache( TileOverlayId tileOverlayId, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('clearTileCache() has not been implemented.'); } @@ -148,7 +148,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// platform side. Future animateCamera( CameraUpdate cameraUpdate, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('animateCamera() has not been implemented.'); } @@ -159,7 +159,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// platform side. Future moveCamera( CameraUpdate cameraUpdate, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('moveCamera() has not been implemented.'); } @@ -176,14 +176,14 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// The style string can be generated using [map style tool](https://mapstyle.withgoogle.com/). Future setMapStyle( String mapStyle, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('setMapStyle() has not been implemented.'); } /// Return the region that is visible in a map. Future getVisibleRegion({ - @required int mapId, + required int mapId, }) { throw UnimplementedError('getVisibleRegion() has not been implemented.'); } @@ -195,7 +195,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// of the map, not necessarily of the whole screen. Future getScreenCoordinate( LatLng latLng, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('getScreenCoordinate() has not been implemented.'); } @@ -207,7 +207,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// of the map, not necessarily of the whole screen. Future getLatLng( ScreenCoordinate screenCoordinate, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('getLatLng() has not been implemented.'); } @@ -222,7 +222,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// * [isMarkerInfoWindowShown] to check if the Info Window is showing. Future showMarkerInfoWindow( MarkerId markerId, { - @required int mapId, + required int mapId, }) { throw UnimplementedError( 'showMarkerInfoWindow() has not been implemented.'); @@ -238,7 +238,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// * [isMarkerInfoWindowShown] to check if the Info Window is showing. Future hideMarkerInfoWindow( MarkerId markerId, { - @required int mapId, + required int mapId, }) { throw UnimplementedError( 'hideMarkerInfoWindow() has not been implemented.'); @@ -252,23 +252,23 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// * See also: /// * [showMarkerInfoWindow] to show the Info Window. /// * [hideMarkerInfoWindow] to hide the Info Window. - Future isMarkerInfoWindowShown( + Future isMarkerInfoWindowShown( MarkerId markerId, { - @required int mapId, + required int mapId, }) { throw UnimplementedError('updateMapOptions() has not been implemented.'); } /// Returns the current zoom level of the map - Future getZoomLevel({ - @required int mapId, + Future getZoomLevel({ + required int mapId, }) { throw UnimplementedError('getZoomLevel() has not been implemented.'); } /// Returns the image bytes of the map - Future takeSnapshot({ - @required int mapId, + Future takeSnapshot({ + required int mapId, }) { throw UnimplementedError('takeSnapshot() has not been implemented.'); } @@ -277,62 +277,62 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { // into the plugin /// The Camera started moving. - Stream onCameraMoveStarted({@required int mapId}) { + Stream onCameraMoveStarted({required int mapId}) { throw UnimplementedError('onCameraMoveStarted() has not been implemented.'); } /// The Camera finished moving to a new [CameraPosition]. - Stream onCameraMove({@required int mapId}) { + Stream onCameraMove({required int mapId}) { throw UnimplementedError('onCameraMove() has not been implemented.'); } /// The Camera is now idle. - Stream onCameraIdle({@required int mapId}) { + Stream onCameraIdle({required int mapId}) { throw UnimplementedError('onCameraMove() has not been implemented.'); } /// A [Marker] has been tapped. - Stream onMarkerTap({@required int mapId}) { + Stream onMarkerTap({required int mapId}) { throw UnimplementedError('onMarkerTap() has not been implemented.'); } /// An [InfoWindow] has been tapped. - Stream onInfoWindowTap({@required int mapId}) { + Stream onInfoWindowTap({required int mapId}) { throw UnimplementedError('onInfoWindowTap() has not been implemented.'); } /// A [Marker] has been dragged to a different [LatLng] position. - Stream onMarkerDragEnd({@required int mapId}) { + Stream onMarkerDragEnd({required int mapId}) { throw UnimplementedError('onMarkerDragEnd() has not been implemented.'); } /// A [Polyline] has been tapped. - Stream onPolylineTap({@required int mapId}) { + Stream onPolylineTap({required int mapId}) { throw UnimplementedError('onPolylineTap() has not been implemented.'); } /// A [Polygon] has been tapped. - Stream onPolygonTap({@required int mapId}) { + Stream onPolygonTap({required int mapId}) { throw UnimplementedError('onPolygonTap() has not been implemented.'); } /// A [Circle] has been tapped. - Stream onCircleTap({@required int mapId}) { + Stream onCircleTap({required int mapId}) { throw UnimplementedError('onCircleTap() has not been implemented.'); } /// A Map has been tapped at a certain [LatLng]. - Stream onTap({@required int mapId}) { + Stream onTap({required int mapId}) { throw UnimplementedError('onTap() has not been implemented.'); } /// A Map has been long-pressed at a certain [LatLng]. - Stream onLongPress({@required int mapId}) { + Stream onLongPress({required int mapId}) { throw UnimplementedError('onLongPress() has not been implemented.'); } /// Dispose of whatever resources the `mapId` is holding on to. - void dispose({@required int mapId}) { + void dispose({required int mapId}) { throw UnimplementedError('dispose() has not been implemented.'); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart index bf5b94d14e45..ce417e972e40 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart @@ -72,20 +72,6 @@ class BitmapDescriptor { return BitmapDescriptor._([_defaultMarker, hue]); } - /// Creates a BitmapDescriptor using the name of a bitmap image in the assets - /// directory. - /// - /// Use [fromAssetImage]. This method does not respect the screen dpi when - /// picking an asset image. - @Deprecated("Use fromAssetImage instead") - static BitmapDescriptor fromAsset(String assetName, {String package}) { - if (package == null) { - return BitmapDescriptor._([_fromAsset, assetName]); - } else { - return BitmapDescriptor._([_fromAsset, assetName, package]); - } - } - /// Creates a [BitmapDescriptor] from an asset image. /// /// Asset images in flutter are stored per: @@ -96,8 +82,8 @@ class BitmapDescriptor { static Future fromAssetImage( ImageConfiguration configuration, String assetName, { - AssetBundle bundle, - String package, + AssetBundle? bundle, + String? package, bool mipmaps = true, }) async { if (!mipmaps && configuration.devicePixelRatio != null) { @@ -111,7 +97,7 @@ class BitmapDescriptor { AssetImage(assetName, package: package, bundle: bundle); final AssetBundleImageKey assetBundleImageKey = await assetImage.obtainKey(configuration); - final Size size = configuration?.size; + final Size? size = configuration.size; return BitmapDescriptor._([ _fromAssetImage, assetBundleImageKey.name, diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart index 48cde883060c..2f9caeb66ff4 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart @@ -4,8 +4,6 @@ import 'dart:ui' show hashValues, Offset; -import 'package:meta/meta.dart' show required; - import 'types.dart'; /// The position of the map "camera", the view point from which the world is shown in the map view. @@ -19,7 +17,7 @@ class CameraPosition { /// null. const CameraPosition({ this.bearing = 0.0, - @required this.target, + required this.target, this.tilt = 0.0, this.zoom = 0.0, }) : assert(bearing != null), @@ -73,11 +71,11 @@ class CameraPosition { /// Deserializes [CameraPosition] from a map. /// /// Mainly for internal use. - static CameraPosition fromMap(dynamic json) { + static CameraPosition? fromMap(dynamic json) { if (json == null) { return null; } - final LatLng target = LatLng.fromJson(json['target']); + final LatLng? target = LatLng.fromJson(json['target']); if (target == null) { return null; } @@ -161,7 +159,7 @@ class CameraUpdate { /// Returns a camera update that modifies the camera zoom level by the /// specified amount. The optional [focus] is a screen point whose underlying /// geographical location should be invariant, if possible, by the movement. - static CameraUpdate zoomBy(double amount, [Offset focus]) { + static CameraUpdate zoomBy(double amount, [Offset? focus]) { if (focus == null) { return CameraUpdate._(['zoomBy', amount]); } else { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart index f9aca33da986..21fe61328d70 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart @@ -4,7 +4,7 @@ import 'package:flutter/foundation.dart' show VoidCallback; import 'package:flutter/material.dart' show Color, Colors; -import 'package:meta/meta.dart' show immutable, required; +import 'package:meta/meta.dart' show immutable; import 'types.dart'; @@ -22,7 +22,7 @@ class CircleId extends MapsObjectId { class Circle implements MapsObject { /// Creates an immutable representation of a [Circle] to draw on [GoogleMap]. const Circle({ - @required this.circleId, + required this.circleId, this.consumeTapEvents = false, this.fillColor = Colors.transparent, this.center = const LatLng(0.0, 0.0), @@ -75,20 +75,20 @@ class Circle implements MapsObject { final int zIndex; /// Callbacks to receive tap events for circle placed on this map. - final VoidCallback onTap; + final VoidCallback? onTap; /// Creates a new [Circle] object whose values are the same as this instance, /// unless overwritten by the specified parameters. Circle copyWith({ - bool consumeTapEventsParam, - Color fillColorParam, - LatLng centerParam, - double radiusParam, - Color strokeColorParam, - int strokeWidthParam, - bool visibleParam, - int zIndexParam, - VoidCallback onTapParam, + bool? consumeTapEventsParam, + Color? fillColorParam, + LatLng? centerParam, + double? radiusParam, + Color? strokeColorParam, + int? strokeWidthParam, + bool? visibleParam, + int? zIndexParam, + VoidCallback? onTapParam, }) { return Circle( circleId: circleId, @@ -111,7 +111,7 @@ class Circle implements MapsObject { dynamic toJson() { final Map json = {}; - void addIfPresent(String fieldName, Object/*?*/ value) { + void addIfPresent(String fieldName, Object? value) { if (value != null) { json[fieldName] = value; } @@ -134,7 +134,7 @@ class Circle implements MapsObject { bool operator ==(Object other) { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; - final Circle typedOther = other; + final Circle typedOther = other as Circle; return circleId == typedOther.circleId && consumeTapEvents == typedOther.consumeTapEvents && fillColor == typedOther.fillColor && diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart index d2b736ce682b..b77b7517df3c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart @@ -34,7 +34,7 @@ class LatLng { } /// Initialize a LatLng from an \[lat, lng\] array. - static LatLng fromJson(Object json) { + static LatLng? fromJson(Object? json) { if (json == null) { return null; } @@ -68,7 +68,7 @@ class LatLngBounds { /// /// The latitude of the southwest corner cannot be larger than the /// latitude of the northeast corner. - LatLngBounds({@required this.southwest, @required this.northeast}) + LatLngBounds({required this.southwest, required this.northeast}) : assert(southwest != null), assert(northeast != null), assert(southwest.latitude <= northeast.latitude); @@ -104,15 +104,15 @@ class LatLngBounds { /// Converts a list to [LatLngBounds]. @visibleForTesting - static LatLngBounds/*?*/ fromList(Object/*?*/ json) { + static LatLngBounds? fromList(Object? json) { if (json == null) { return null; } assert(json is List && json.length == 2); final list = json as List; return LatLngBounds( - southwest: LatLng.fromJson(list[0]), - northeast: LatLng.fromJson(list[1]), + southwest: LatLng.fromJson(list[0])!, + northeast: LatLng.fromJson(list[1])!, ); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart index 8566e02cb510..1023cbfb8165 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart @@ -23,7 +23,7 @@ class MapsObjectId { bool operator ==(Object other) { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; - final MapsObjectId typedOther = other; + final MapsObjectId typedOther = other as MapsObjectId; return value == typedOther.value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart index ac32cc53d68c..6c88afab3882 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart @@ -5,7 +5,6 @@ import 'dart:ui' show hashValues, hashList; import 'package:flutter/foundation.dart' show objectRuntimeType, setEquals; -import 'package:meta/meta.dart' show required; import 'maps_object.dart'; import 'utils/maps_object.dart'; @@ -18,9 +17,9 @@ class MapsObjectUpdates { /// dictionary. E.g., 'circle' will give 'circlesToAdd', 'circlesToUpdate', /// 'circleIdsToRemove'. MapsObjectUpdates.from( - Set previous, + Set? previous, Set current, { - @required this.objectName, + required this.objectName, }) { if (previous == null) { previous = Set.identity(); @@ -40,8 +39,8 @@ class MapsObjectUpdates { /// /// It is a programming error to call this with an ID that is not guaranteed /// to be in [currentObjects]. - T/*!*/ _idToCurrentObject(MapsObjectId id) { - return currentObjects[id]; + T _idToCurrentObject(MapsObjectId id) { + return currentObjects[id]!; } _objectIdsToRemove = previousObjectIds.difference(currentObjectIds); @@ -54,7 +53,7 @@ class MapsObjectUpdates { // Returns `true` if [current] is not equals to previous one with the // same id. bool hasChanged(T current) { - final T previous = previousObjects[current.mapsId]; + final T? previous = previousObjects[current.mapsId as MapsObjectId]; return current != previous; } @@ -73,27 +72,27 @@ class MapsObjectUpdates { return _objectsToAdd; } - /*late*/ Set _objectsToAdd; + late Set _objectsToAdd; /// Set of objects to be removed in this update. Set> get objectIdsToRemove { return _objectIdsToRemove; } - /*late*/ Set> _objectIdsToRemove; + late Set> _objectIdsToRemove; /// Set of objects to be changed in this update. Set get objectsToChange { return _objectsToChange; } - /*late*/ Set _objectsToChange; + late Set _objectsToChange; /// Converts this object to JSON. Map toJson() { final Map updateMap = {}; - void addIfNonNull(String fieldName, Object /*?*/ value) { + void addIfNonNull(String fieldName, Object? value) { if (value != null) { updateMap[fieldName] = value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart index 4969e5edb1e1..15d7269420d2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart @@ -5,7 +5,7 @@ import 'dart:ui' show hashValues, Offset; import 'package:flutter/foundation.dart' show ValueChanged, VoidCallback; -import 'package:meta/meta.dart' show immutable, required; +import 'package:meta/meta.dart' show immutable; import 'types.dart'; @@ -32,12 +32,12 @@ class InfoWindow { /// Text displayed in an info window when the user taps the marker. /// /// A null value means no title. - final String title; + final String? title; /// Additional text displayed below the [title]. /// /// A null value means no additional text. - final String snippet; + final String? snippet; /// The icon image point that will be the anchor of the info window when /// displayed. @@ -48,15 +48,15 @@ class InfoWindow { final Offset anchor; /// onTap callback for this [InfoWindow]. - final VoidCallback onTap; + final VoidCallback? onTap; /// Creates a new [InfoWindow] object whose values are the same as this instance, /// unless overwritten by the specified parameters. InfoWindow copyWith({ - String titleParam, - String snippetParam, - Offset anchorParam, - VoidCallback onTapParam, + String? titleParam, + String? snippetParam, + Offset? anchorParam, + VoidCallback? onTapParam, }) { return InfoWindow( title: titleParam ?? title, @@ -69,7 +69,7 @@ class InfoWindow { dynamic _toJson() { final Map json = {}; - void addIfPresent(String fieldName, Object/*?*/ value) { + void addIfPresent(String fieldName, Object? value) { if (value != null) { json[fieldName] = value; } @@ -86,7 +86,7 @@ class InfoWindow { bool operator ==(Object other) { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; - final InfoWindow typedOther = other; + final InfoWindow typedOther = other as InfoWindow; return title == typedOther.title && snippet == typedOther.snippet && anchor == typedOther.anchor; @@ -137,7 +137,7 @@ class Marker implements MapsObject { /// * reports [onTap] events /// * reports [onDragEnd] events const Marker({ - @required this.markerId, + required this.markerId, this.alpha = 1.0, this.anchor = const Offset(0.5, 1.0), this.consumeTapEvents = false, @@ -208,27 +208,27 @@ class Marker implements MapsObject { final double zIndex; /// Callbacks to receive tap events for markers placed on this map. - final VoidCallback onTap; + final VoidCallback? onTap; /// Signature reporting the new [LatLng] at the end of a drag event. - final ValueChanged onDragEnd; + final ValueChanged? onDragEnd; /// Creates a new [Marker] object whose values are the same as this instance, /// unless overwritten by the specified parameters. Marker copyWith({ - double alphaParam, - Offset anchorParam, - bool consumeTapEventsParam, - bool draggableParam, - bool flatParam, - BitmapDescriptor iconParam, - InfoWindow infoWindowParam, - LatLng positionParam, - double rotationParam, - bool visibleParam, - double zIndexParam, - VoidCallback onTapParam, - ValueChanged onDragEndParam, + double? alphaParam, + Offset? anchorParam, + bool? consumeTapEventsParam, + bool? draggableParam, + bool? flatParam, + BitmapDescriptor? iconParam, + InfoWindow? infoWindowParam, + LatLng? positionParam, + double? rotationParam, + bool? visibleParam, + double? zIndexParam, + VoidCallback? onTapParam, + ValueChanged? onDragEndParam, }) { return Marker( markerId: markerId, @@ -255,7 +255,7 @@ class Marker implements MapsObject { Map toJson() { final Map json = {}; - void addIfPresent(String fieldName, Object/*?*/ value) { + void addIfPresent(String fieldName, Object? value) { if (value != null) { json[fieldName] = value; } @@ -267,9 +267,9 @@ class Marker implements MapsObject { addIfPresent('consumeTapEvents', consumeTapEvents); addIfPresent('draggable', draggable); addIfPresent('flat', flat); - addIfPresent('icon', icon?.toJson()); - addIfPresent('infoWindow', infoWindow?._toJson()); - addIfPresent('position', position?.toJson()); + addIfPresent('icon', icon.toJson()); + addIfPresent('infoWindow', infoWindow._toJson()); + addIfPresent('position', position.toJson()); addIfPresent('rotation', rotation); addIfPresent('visible', visible); addIfPresent('zIndex', zIndex); @@ -280,7 +280,7 @@ class Marker implements MapsObject { bool operator ==(Object other) { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; - final Marker typedOther = other; + final Marker typedOther = other as Marker; return markerId == typedOther.markerId && alpha == typedOther.alpha && anchor == typedOther.anchor && diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart index 504464c9b090..13ac417c7a55 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart @@ -5,7 +5,7 @@ import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart' show listEquals, VoidCallback; import 'package:flutter/material.dart' show Color, Colors; -import 'package:meta/meta.dart' show immutable, required; +import 'package:meta/meta.dart' show immutable; import 'types.dart'; @@ -23,7 +23,7 @@ class PolygonId extends MapsObjectId { class Polygon implements MapsObject { /// Creates an immutable representation of a polygon through geographical locations on the map. const Polygon({ - @required this.polygonId, + required this.polygonId, this.consumeTapEvents = false, this.fillColor = Colors.black, this.geodesic = false, @@ -91,21 +91,21 @@ class Polygon implements MapsObject { final int zIndex; /// Callbacks to receive tap events for polygon placed on this map. - final VoidCallback onTap; + final VoidCallback? onTap; /// Creates a new [Polygon] object whose values are the same as this instance, /// unless overwritten by the specified parameters. Polygon copyWith({ - bool consumeTapEventsParam, - Color fillColorParam, - bool geodesicParam, - List pointsParam, - List> holesParam, - Color strokeColorParam, - int strokeWidthParam, - bool visibleParam, - int zIndexParam, - VoidCallback onTapParam, + bool? consumeTapEventsParam, + Color? fillColorParam, + bool? geodesicParam, + List? pointsParam, + List>? holesParam, + Color? strokeColorParam, + int? strokeWidthParam, + bool? visibleParam, + int? zIndexParam, + VoidCallback? onTapParam, }) { return Polygon( polygonId: polygonId, @@ -131,7 +131,7 @@ class Polygon implements MapsObject { dynamic toJson() { final Map json = {}; - void addIfPresent(String fieldName, Object/*?*/ value) { + void addIfPresent(String fieldName, Object? value) { if (value != null) { json[fieldName] = value; } @@ -161,7 +161,7 @@ class Polygon implements MapsObject { bool operator ==(Object other) { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; - final Polygon typedOther = other; + final Polygon typedOther = other as Polygon; return polygonId == typedOther.polygonId && consumeTapEvents == typedOther.consumeTapEvents && fillColor == typedOther.fillColor && diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart index c4fd8273f127..5f6d874f885f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart @@ -4,7 +4,7 @@ import 'package:flutter/foundation.dart' show listEquals, VoidCallback; import 'package:flutter/material.dart' show Color, Colors; -import 'package:meta/meta.dart' show immutable, required; +import 'package:meta/meta.dart' show immutable; import 'types.dart'; @@ -24,7 +24,7 @@ class PolylineId extends MapsObjectId { class Polyline implements MapsObject { /// Creates an immutable object representing a line drawn through geographical locations on the map. const Polyline({ - @required this.polylineId, + required this.polylineId, this.consumeTapEvents = false, this.color = Colors.black, this.endCap = Cap.buttCap, @@ -113,23 +113,23 @@ class Polyline implements MapsObject { final int zIndex; /// Callbacks to receive tap events for polyline placed on this map. - final VoidCallback onTap; + final VoidCallback? onTap; /// Creates a new [Polyline] object whose values are the same as this instance, /// unless overwritten by the specified parameters. Polyline copyWith({ - Color colorParam, - bool consumeTapEventsParam, - Cap endCapParam, - bool geodesicParam, - JointType jointTypeParam, - List patternsParam, - List pointsParam, - Cap startCapParam, - bool visibleParam, - int widthParam, - int zIndexParam, - VoidCallback onTapParam, + Color? colorParam, + bool? consumeTapEventsParam, + Cap? endCapParam, + bool? geodesicParam, + JointType? jointTypeParam, + List? patternsParam, + List? pointsParam, + Cap? startCapParam, + bool? visibleParam, + int? widthParam, + int? zIndexParam, + VoidCallback? onTapParam, }) { return Polyline( polylineId: polylineId, @@ -161,7 +161,7 @@ class Polyline implements MapsObject { dynamic toJson() { final Map json = {}; - void addIfPresent(String fieldName, Object/*?*/ value) { + void addIfPresent(String fieldName, Object? value) { if (value != null) { json[fieldName] = value; } @@ -170,10 +170,10 @@ class Polyline implements MapsObject { addIfPresent('polylineId', polylineId.value); addIfPresent('consumeTapEvents', consumeTapEvents); addIfPresent('color', color.value); - addIfPresent('endCap', endCap?.toJson()); + addIfPresent('endCap', endCap.toJson()); addIfPresent('geodesic', geodesic); - addIfPresent('jointType', jointType?.value); - addIfPresent('startCap', startCap?.toJson()); + addIfPresent('jointType', jointType.value); + addIfPresent('startCap', startCap.toJson()); addIfPresent('visible', visible); addIfPresent('width', width); addIfPresent('zIndex', zIndex); @@ -193,7 +193,7 @@ class Polyline implements MapsObject { bool operator ==(Object other) { if (identical(this, other)) return true; if (other.runtimeType != runtimeType) return false; - final Polyline typedOther = other; + final Polyline typedOther = other as Polyline; return polylineId == typedOther.polylineId && consumeTapEvents == typedOther.consumeTapEvents && color == typedOther.color && diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart index f9f34ea31837..dc4e72bc358d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart @@ -4,7 +4,7 @@ import 'dart:ui' show hashValues; -import 'package:meta/meta.dart' show immutable, required; +import 'package:meta/meta.dart' show immutable; /// Represents a point coordinate in the [GoogleMap]'s view. /// @@ -15,19 +15,19 @@ import 'package:meta/meta.dart' show immutable, required; class ScreenCoordinate { /// Creates an immutable representation of a point coordinate in the [GoogleMap]'s view. const ScreenCoordinate({ - @required this.x, - @required this.y, + required this.x, + required this.y, }); /// Represents the number of pixels from the left of the [GoogleMap]. - final int/*!*/ x; + final int x; /// Represents the number of pixels from the top of the [GoogleMap]. - final int/*!*/ y; + final int y; /// Converts this object to something serializable in JSON. dynamic toJson() { - return { + return { "x": x, "y": y, }; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart index 6c29f076bb0b..1f4bdbc02ab6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart @@ -12,22 +12,22 @@ class Tile { const Tile(this.width, this.height, this.data); /// The width of the image encoded by data in logical pixels. - final int/*!*/ width; + final int width; /// The height of the image encoded by data in logical pixels. - final int/*!*/ height; + final int height; /// A byte array containing the image data. /// /// The image data format must be natively supported for decoding by the platform. /// e.g on Android it can only be one of the [supported image formats for decoding](https://developer.android.com/guide/topics/media/media-formats#image-formats). - final Uint8List data; + final Uint8List? data; /// Converts this object to JSON. Map toJson() { final Map json = {}; - void addIfPresent(String fieldName, Object/*?*/ value) { + void addIfPresent(String fieldName, Object? value) { if (value != null) { json[fieldName] = value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart index f9e979e0b49f..d07581bd187e 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart @@ -6,7 +6,7 @@ import 'dart:ui' show hashValues; import 'package:flutter/foundation.dart'; import 'types.dart'; -import 'package:meta/meta.dart' show immutable, required; +import 'package:meta/meta.dart' show immutable; /// Uniquely identifies a [TileOverlay] among [GoogleMap] tile overlays. @immutable @@ -47,7 +47,7 @@ class TileOverlayId extends MapsObjectId { class TileOverlay implements MapsObject { /// Creates an immutable representation of a [TileOverlay] to draw on [GoogleMap]. const TileOverlay({ - @required this.tileOverlayId, + required this.tileOverlayId, this.fadeIn = true, this.tileProvider, this.transparency = 0.0, @@ -57,7 +57,7 @@ class TileOverlay implements MapsObject { }) : assert(transparency >= 0.0 && transparency <= 1.0); /// Uniquely identifies a [TileOverlay]. - final TileOverlayId/*!*/ tileOverlayId; + final TileOverlayId tileOverlayId; @override TileOverlayId get mapsId => tileOverlayId; @@ -66,7 +66,7 @@ class TileOverlay implements MapsObject { final bool fadeIn; /// The tile provider to use for this tile overlay. - final TileProvider tileProvider; + final TileProvider? tileProvider; /// The transparency of the tile overlay. The default transparency is 0 (opaque). final double transparency; @@ -90,11 +90,11 @@ class TileOverlay implements MapsObject { /// Creates a new [TileOverlay] object whose values are the same as this instance, /// unless overwritten by the specified parameters. TileOverlay copyWith({ - bool fadeInParam, - double transparencyParam, - int zIndexParam, - bool visibleParam, - int tileSizeParam, + bool? fadeInParam, + double? transparencyParam, + int? zIndexParam, + bool? visibleParam, + int? tileSizeParam, }) { return TileOverlay( tileOverlayId: tileOverlayId, @@ -112,7 +112,7 @@ class TileOverlay implements MapsObject { Map toJson() { final Map json = {}; - void addIfPresent(String fieldName, Object/*?*/ value) { + void addIfPresent(String fieldName, Object? value) { if (value != null) { json[fieldName] = value; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart index 6fe9622fd438..8ad6eeffdcd4 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart @@ -7,7 +7,7 @@ import 'types.dart'; /// Update specification for a set of [TileOverlay]s. class TileOverlayUpdates extends MapsObjectUpdates { /// Computes [TileOverlayUpdates] given previous and current [TileOverlay]s. - TileOverlayUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'tileOverlay'); + TileOverlayUpdates.from(Set? previous, Set current) : super.from(previous, current, objectName: 'tileOverlay'); /// Set of TileOverlays to be added in this update. Set get tileOverlaysToAdd => objectsToAdd; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_provider.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_provider.dart index 50088d84243c..abaf38ba719d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_provider.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_provider.dart @@ -12,5 +12,5 @@ abstract class TileProvider { /// Returns the tile to be used for this tile coordinate. /// /// See [TileOverlay] for the specification of tile coordinates. - Future getTile(int/*!*/ x, int/*!*/ y, int zoom); + Future getTile(int x, int y, int? zoom); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/ui.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/ui.dart index 8d84171bac03..f56acf19ec06 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/ui.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/ui.dart @@ -39,7 +39,7 @@ class CameraTargetBounds { /// The geographical bounding box for the map camera target. /// /// A null value means the camera target is unbounded. - final LatLngBounds bounds; + final LatLngBounds? bounds; /// Unbounded camera target. static const CameraTargetBounds unbounded = CameraTargetBounds(null); @@ -76,10 +76,10 @@ class MinMaxZoomPreference { : assert(minZoom == null || maxZoom == null || minZoom <= maxZoom); /// The preferred minimum zoom level or null, if unbounded from below. - final double minZoom; + final double? minZoom; /// The preferred maximum zoom level or null, if unbounded from above. - final double maxZoom; + final double? maxZoom; /// Unbounded zooming. static const MinMaxZoomPreference unbounded = diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart index 6b875890ec7c..62475d0ec1a0 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart @@ -6,11 +6,11 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Circles in a Map of CircleId -> Circle. -Map keyByCircleId(Iterable/*?*/ circles) { +Map keyByCircleId(Iterable? circles) { return keyByMapsObjectId(circles).cast(); } /// Converts a Set of Circles into something serializable in JSON. -List> serializeCircleSet(Set circles) { +List>? serializeCircleSet(Set circles) { return serializeMapsObjectSet(circles); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart index e7a86b66a269..3094b977c9fa 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart @@ -5,17 +5,17 @@ import '../maps_object.dart'; /// Converts an [Iterable] of [MapsObject]s in a Map of [MapObjectId] -> [MapObject]. -Map, T> keyByMapsObjectId(Iterable objects) { +Map, T> keyByMapsObjectId(Iterable? objects) { if (objects == null) { return , T>{}; } return Map, T>.fromEntries(objects.map((T object) => - MapEntry, T>(object.mapsId, object.clone()))); + MapEntry, T>(object.mapsId as MapsObjectId, object.clone()))); } /// Converts a Set of [MapsObject]s into something serializable in JSON. -List> serializeMapsObjectSet( - Set mapsObjects) { +List>? serializeMapsObjectSet( + Set? mapsObjects) { if (mapsObjects == null) { return null; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart index a95b60b513db..8888f422d1be 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart @@ -6,11 +6,11 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Markers in a Map of MarkerId -> Marker. -Map keyByMarkerId(Iterable/*?*/ markers) { +Map keyByMarkerId(Iterable? markers) { return keyByMapsObjectId(markers).cast(); } /// Converts a Set of Markers into something serializable in JSON. -List> serializeMarkerSet(Set markers) { +List>? serializeMarkerSet(Set markers) { return serializeMapsObjectSet(markers); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart index eb8b378e9361..73a7164f2e02 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart @@ -6,11 +6,11 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Polygons in a Map of PolygonId -> Polygon. -Map keyByPolygonId(Iterable/*?*/ polygons) { +Map keyByPolygonId(Iterable? polygons) { return keyByMapsObjectId(polygons).cast(); } /// Converts a Set of Polygons into something serializable in JSON. -List> serializePolygonSet(Set polygons) { +List>? serializePolygonSet(Set polygons) { return serializeMapsObjectSet(polygons); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart index 5bab00470fff..e44d78dea159 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart @@ -6,11 +6,11 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Polylines in a Map of PolylineId -> Polyline. -Map keyByPolylineId(Iterable/*?*/ polylines) { +Map keyByPolylineId(Iterable? polylines) { return keyByMapsObjectId(polylines).cast(); } /// Converts a Set of Polylines into something serializable in JSON. -List> serializePolylineSet(Set polylines) { +List>? serializePolylineSet(Set polylines) { return serializeMapsObjectSet(polylines); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart index ab0fd601a7b5..a87f7551a9b9 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart @@ -7,12 +7,12 @@ import 'maps_object.dart'; /// Converts an [Iterable] of TileOverlay in a Map of TileOverlayId -> TileOverlay. Map keyTileOverlayId( - Iterable/*?*/ tileOverlays) { + Iterable? tileOverlays) { return keyByMapsObjectId(tileOverlays).cast(); } /// Converts a Set of TileOverlays into something serializable in JSON. -List> serializeTileOverlaySet( +List>? serializeTileOverlaySet( Set tileOverlays) { return serializeMapsObjectSet(tileOverlays); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml index c62b7a9ebbeb..69699be4c8e5 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml @@ -20,5 +20,5 @@ dev_dependencies: pedantic: ^1.8.0 environment: - sdk: ">=2.3.0 <3.0.0" + sdk: '>=2.12.0-0 <3.0.0' flutter: ">=1.9.1+hotfix.4" diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_test.dart index 0be9a7cea8f0..03ecd3c41a49 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_test.dart @@ -19,10 +19,12 @@ void main() { expect(json['data'], data); }); - test('toJson returns empty if nothing presents', () async { - final Tile tile = Tile(null, null, null); + test('toJson handles null data', () async { + final Tile tile = Tile(0, 0, null); final Map json = tile.toJson(); - expect(json.isEmpty, true); + expect(json['width'], 0); + expect(json['height'], 0); + expect(json['data'], isNull); }); }); } From 85ac08bbd1f8a8bd9ae1f2917a037a1beb899b51 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 10 Feb 2021 10:16:53 -0500 Subject: [PATCH 06/14] Update version --- .../google_maps_flutter_platform_interface/CHANGELOG.md | 4 ++++ .../google_maps_flutter_platform_interface/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md index 4273f596cf39..1043cfa4b2a2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.0-nullsafety + +* Migrated to null-safety. + ## 1.2.0 * Add TileOverlay support. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml index 69699be4c8e5..8b31feeb94a2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the google_maps_flutter plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 1.2.0 +version: 2.0.0-nullsafety dependencies: flutter: From 20ad64eb05692c0518cdd8cb72b036466d3f182f Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 10 Feb 2021 11:38:23 -0500 Subject: [PATCH 07/14] Adjustments from migrating app-facing package --- .../method_channel_google_maps_flutter.dart | 2 +- .../google_maps_flutter_platform.dart | 2 +- .../lib/src/types/utils/circle.dart | 2 +- .../lib/src/types/utils/maps_object.dart | 12 +-- .../lib/src/types/utils/marker.dart | 2 +- .../lib/src/types/utils/polygon.dart | 2 +- .../lib/src/types/utils/polyline.dart | 2 +- .../lib/src/types/utils/tile_overlay.dart | 2 +- .../test/types/maps_object_test.dart | 73 ++++++++----------- 9 files changed, 40 insertions(+), 59 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index 63b3f470df63..bc15f7860e62 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -543,7 +543,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Widget buildView( Map creationParams, - Set> gestureRecognizers, + Set>? gestureRecognizers, PlatformViewCreatedCallback onPlatformViewCreated) { if (defaultTargetPlatform == TargetPlatform.android) { return AndroidView( diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart index 92bee870ebe3..e1eed8750f4c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart @@ -339,7 +339,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// Returns a widget displaying the map view Widget buildView( Map creationParams, - Set> gestureRecognizers, + Set>? gestureRecognizers, PlatformViewCreatedCallback onPlatformViewCreated) { throw UnimplementedError('buildView() has not been implemented.'); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart index 62475d0ec1a0..6d716a7de915 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart @@ -6,7 +6,7 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Circles in a Map of CircleId -> Circle. -Map keyByCircleId(Iterable? circles) { +Map keyByCircleId(Iterable circles) { return keyByMapsObjectId(circles).cast(); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart index 3094b977c9fa..7134167994bf 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart @@ -5,20 +5,14 @@ import '../maps_object.dart'; /// Converts an [Iterable] of [MapsObject]s in a Map of [MapObjectId] -> [MapObject]. -Map, T> keyByMapsObjectId(Iterable? objects) { - if (objects == null) { - return , T>{}; - } +Map, T> keyByMapsObjectId(Iterable objects) { return Map, T>.fromEntries(objects.map((T object) => MapEntry, T>(object.mapsId as MapsObjectId, object.clone()))); } /// Converts a Set of [MapsObject]s into something serializable in JSON. -List>? serializeMapsObjectSet( - Set? mapsObjects) { - if (mapsObjects == null) { - return null; - } +List> serializeMapsObjectSet( + Set mapsObjects) { return mapsObjects .map>((MapsObject p) => p.toJson()) .toList(); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart index 8888f422d1be..72c0d878bdc5 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart @@ -6,7 +6,7 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Markers in a Map of MarkerId -> Marker. -Map keyByMarkerId(Iterable? markers) { +Map keyByMarkerId(Iterable markers) { return keyByMapsObjectId(markers).cast(); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart index 73a7164f2e02..4bce47b56b1d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart @@ -6,7 +6,7 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Polygons in a Map of PolygonId -> Polygon. -Map keyByPolygonId(Iterable? polygons) { +Map keyByPolygonId(Iterable polygons) { return keyByMapsObjectId(polygons).cast(); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart index e44d78dea159..380747107e59 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart @@ -6,7 +6,7 @@ import '../types.dart'; import 'maps_object.dart'; /// Converts an [Iterable] of Polylines in a Map of PolylineId -> Polyline. -Map keyByPolylineId(Iterable? polylines) { +Map keyByPolylineId(Iterable polylines) { return keyByMapsObjectId(polylines).cast(); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart index a87f7551a9b9..9b8bac722256 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart @@ -7,7 +7,7 @@ import 'maps_object.dart'; /// Converts an [Iterable] of TileOverlay in a Map of TileOverlayId -> TileOverlay. Map keyTileOverlayId( - Iterable? tileOverlays) { + Iterable tileOverlays) { return keyByMapsObjectId(tileOverlays).cast(); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart index bba924c3225e..310201b6c2bf 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart @@ -11,50 +11,37 @@ import 'test_maps_object.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); - group('keyByMapsObjectId tests', () { - test('normal', () async { - final MapsObjectId id1 = - MapsObjectId('1'); - final MapsObjectId id2 = - MapsObjectId('2'); - final MapsObjectId id3 = - MapsObjectId('3'); - final TestMapsObject object1 = TestMapsObject(id1); - final TestMapsObject object2 = TestMapsObject(id2, data: 2); - final TestMapsObject object3 = TestMapsObject(id3); - expect( - keyByMapsObjectId({object1, object2, object3}), - , TestMapsObject>{ - id1: object1, - id2: object2, - id3: object3, - }); - }); - - test('null', () async { - expect(keyByMapsObjectId(null), - , TestMapsObject>{}); - }); + test('keyByMapsObjectId', () async { + final MapsObjectId id1 = + MapsObjectId('1'); + final MapsObjectId id2 = + MapsObjectId('2'); + final MapsObjectId id3 = + MapsObjectId('3'); + final TestMapsObject object1 = TestMapsObject(id1); + final TestMapsObject object2 = TestMapsObject(id2, data: 2); + final TestMapsObject object3 = TestMapsObject(id3); + expect( + keyByMapsObjectId({object1, object2, object3}), + , TestMapsObject>{ + id1: object1, + id2: object2, + id3: object3, + }); }); - group('serializeMapsObjectSet tests', () { - test('normal', () async { - final MapsObjectId id1 = - MapsObjectId('1'); - final MapsObjectId id2 = - MapsObjectId('2'); - final MapsObjectId id3 = - MapsObjectId('3'); - final TestMapsObject object1 = TestMapsObject(id1); - final TestMapsObject object2 = TestMapsObject(id2, data: 2); - final TestMapsObject object3 = TestMapsObject(id3); - expect( - serializeMapsObjectSet({object1, object2, object3}), - >[{'id': '1'}, {'id': '2'}, {'id': '3'}]); - }); - - test('null', () async { - expect(serializeMapsObjectSet(null), isNull); - }); + test('serializeMapsObjectSet', () async { + final MapsObjectId id1 = + MapsObjectId('1'); + final MapsObjectId id2 = + MapsObjectId('2'); + final MapsObjectId id3 = + MapsObjectId('3'); + final TestMapsObject object1 = TestMapsObject(id1); + final TestMapsObject object2 = TestMapsObject(id2, data: 2); + final TestMapsObject object3 = TestMapsObject(id3); + expect( + serializeMapsObjectSet({object1, object2, object3}), + >[{'id': '1'}, {'id': '2'}, {'id': '3'}]); }); } From 9d504d60d4cb2e5f776eba7c69c25a2966b4ca25 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 11 Feb 2021 13:36:59 -0500 Subject: [PATCH 08/14] More interface tweaks --- .../method_channel_google_maps_flutter.dart | 18 +++++++++--------- .../google_maps_flutter_platform.dart | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index bc15f7860e62..1c8b71e00469 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -410,11 +410,11 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// style reference for more information regarding the supported styles. @override Future setMapStyle( - String mapStyle, { + String? mapStyle, { required int mapId, }) async { - final List successAndError = await (channel(mapId) - .invokeMethod>('map#setStyle', mapStyle) as FutureOr>); + final List successAndError = (await channel(mapId) + .invokeMethod>('map#setStyle', mapStyle))!; final bool success = successAndError[0]; if (!success) { throw MapStyleException(successAndError[1]); @@ -426,8 +426,8 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { Future getVisibleRegion({ required int mapId, }) async { - final Map latLngBounds = await (channel(mapId) - .invokeMapMethod('map#getVisibleRegion') as FutureOr>); + final Map latLngBounds = (await channel(mapId) + .invokeMapMethod('map#getVisibleRegion'))!; final LatLng southwest = LatLng.fromJson(latLngBounds['southwest'])!; final LatLng northeast = LatLng.fromJson(latLngBounds['northeast'])!; @@ -444,9 +444,9 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { LatLng latLng, { required int mapId, }) async { - final Map point = await (channel(mapId) + final Map point = (await channel(mapId) .invokeMapMethod( - 'map#getScreenCoordinate', latLng.toJson()) as FutureOr>); + 'map#getScreenCoordinate', latLng.toJson()))!; return ScreenCoordinate(x: point['x']!, y: point['y']!); } @@ -460,9 +460,9 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { ScreenCoordinate screenCoordinate, { required int mapId, }) async { - final List latLng = await (channel(mapId) + final List latLng = (await channel(mapId) .invokeMethod>( - 'map#getLatLng', screenCoordinate.toJson()) as FutureOr>); + 'map#getLatLng', screenCoordinate.toJson()))!; return LatLng(latLng[0], latLng[1]); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart index e1eed8750f4c..6baaf6c38864 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart @@ -175,7 +175,7 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// /// The style string can be generated using [map style tool](https://mapstyle.withgoogle.com/). Future setMapStyle( - String mapStyle, { + String? mapStyle, { required int mapId, }) { throw UnimplementedError('setMapStyle() has not been implemented.'); From c122ad362d107a3831ef4a8c59afe9d62008eb6a Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 11 Feb 2021 16:36:25 -0500 Subject: [PATCH 09/14] Autoformat --- .../method_channel_google_maps_flutter.dart | 3 ++- .../lib/src/types/circle_updates.dart | 3 ++- .../lib/src/types/marker_updates.dart | 3 ++- .../lib/src/types/polygon_updates.dart | 3 ++- .../lib/src/types/polyline_updates.dart | 6 +++-- .../lib/src/types/tile_overlay_updates.dart | 6 +++-- .../lib/src/types/utils/maps_object.dart | 9 +++---- .../lib/src/types/utils/tile_overlay.dart | 3 ++- .../test/types/maps_object_test.dart | 24 +++++++++---------- 9 files changed, 34 insertions(+), 26 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index 1c8b71e00469..3f2f08e2e4d7 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -525,7 +525,8 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { Future getZoomLevel({ required int mapId, }) { - return channel(mapId).invokeMethod('map#getZoomLevel') as Future; + return channel(mapId).invokeMethod('map#getZoomLevel') + as Future; } /// Returns the image bytes of the map diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart index 7c8afbec5bd9..a0b064b7be2a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle_updates.dart @@ -10,7 +10,8 @@ import 'types.dart'; // (Do not re-export) class CircleUpdates extends MapsObjectUpdates { /// Computes [CircleUpdates] given previous and current [Circle]s. - CircleUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'circle'); + CircleUpdates.from(Set previous, Set current) + : super.from(previous, current, objectName: 'circle'); /// Set of Circles to be added in this update. Set get circlesToAdd => objectsToAdd; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker_updates.dart index 1675b5272718..9c96ab63af18 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker_updates.dart @@ -10,7 +10,8 @@ import 'types.dart'; // (Do not re-export) class MarkerUpdates extends MapsObjectUpdates { /// Computes [MarkerUpdates] given previous and current [Marker]s. - MarkerUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'marker'); + MarkerUpdates.from(Set previous, Set current) + : super.from(previous, current, objectName: 'marker'); /// Set of Markers to be added in this update. Set get markersToAdd => objectsToAdd; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon_updates.dart index 6b9ac7957936..29b74aecbd66 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon_updates.dart @@ -10,7 +10,8 @@ import 'types.dart'; // (Do not re-export) class PolygonUpdates extends MapsObjectUpdates { /// Computes [PolygonUpdates] given previous and current [Polygon]s. - PolygonUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'polygon'); + PolygonUpdates.from(Set previous, Set current) + : super.from(previous, current, objectName: 'polygon'); /// Set of Polygons to be added in this update. Set get polygonsToAdd => objectsToAdd; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline_updates.dart index 1ae4017d9c45..60e0bfe6c7ce 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline_updates.dart @@ -10,13 +10,15 @@ import 'types.dart'; // (Do not re-export) class PolylineUpdates extends MapsObjectUpdates { /// Computes [PolylineUpdates] given previous and current [Polyline]s. - PolylineUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'polyline'); + PolylineUpdates.from(Set previous, Set current) + : super.from(previous, current, objectName: 'polyline'); /// Set of Polylines to be added in this update. Set get polylinesToAdd => objectsToAdd; /// Set of PolylineIds to be removed in this update. - Set get polylineIdsToRemove => objectIdsToRemove.cast(); + Set get polylineIdsToRemove => + objectIdsToRemove.cast(); /// Set of Polylines to be changed in this update. Set get polylinesToChange => objectsToChange; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart index 8ad6eeffdcd4..02b96bf4bd34 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart @@ -7,13 +7,15 @@ import 'types.dart'; /// Update specification for a set of [TileOverlay]s. class TileOverlayUpdates extends MapsObjectUpdates { /// Computes [TileOverlayUpdates] given previous and current [TileOverlay]s. - TileOverlayUpdates.from(Set? previous, Set current) : super.from(previous, current, objectName: 'tileOverlay'); + TileOverlayUpdates.from(Set? previous, Set current) + : super.from(previous, current, objectName: 'tileOverlay'); /// Set of TileOverlays to be added in this update. Set get tileOverlaysToAdd => objectsToAdd; /// Set of TileOverlayIds to be removed in this update. - Set get tileOverlayIdsToRemove => objectIdsToRemove.cast(); + Set get tileOverlayIdsToRemove => + objectIdsToRemove.cast(); /// Set of TileOverlays to be changed in this update. Set get tileOverlaysToChange => objectsToChange; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart index 7134167994bf..3b0988dffd13 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart @@ -5,14 +5,15 @@ import '../maps_object.dart'; /// Converts an [Iterable] of [MapsObject]s in a Map of [MapObjectId] -> [MapObject]. -Map, T> keyByMapsObjectId(Iterable objects) { +Map, T> keyByMapsObjectId( + Iterable objects) { return Map, T>.fromEntries(objects.map((T object) => - MapEntry, T>(object.mapsId as MapsObjectId, object.clone()))); + MapEntry, T>( + object.mapsId as MapsObjectId, object.clone()))); } /// Converts a Set of [MapsObject]s into something serializable in JSON. -List> serializeMapsObjectSet( - Set mapsObjects) { +List> serializeMapsObjectSet(Set mapsObjects) { return mapsObjects .map>((MapsObject p) => p.toJson()) .toList(); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart index 9b8bac722256..5a80612c0648 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart @@ -8,7 +8,8 @@ import 'maps_object.dart'; /// Converts an [Iterable] of TileOverlay in a Map of TileOverlayId -> TileOverlay. Map keyTileOverlayId( Iterable tileOverlays) { - return keyByMapsObjectId(tileOverlays).cast(); + return keyByMapsObjectId(tileOverlays) + .cast(); } /// Converts a Set of TileOverlays into something serializable in JSON. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart index 310201b6c2bf..5d9878bc588c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart @@ -12,12 +12,9 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); test('keyByMapsObjectId', () async { - final MapsObjectId id1 = - MapsObjectId('1'); - final MapsObjectId id2 = - MapsObjectId('2'); - final MapsObjectId id3 = - MapsObjectId('3'); + final MapsObjectId id1 = MapsObjectId('1'); + final MapsObjectId id2 = MapsObjectId('2'); + final MapsObjectId id3 = MapsObjectId('3'); final TestMapsObject object1 = TestMapsObject(id1); final TestMapsObject object2 = TestMapsObject(id2, data: 2); final TestMapsObject object3 = TestMapsObject(id3); @@ -31,17 +28,18 @@ void main() { }); test('serializeMapsObjectSet', () async { - final MapsObjectId id1 = - MapsObjectId('1'); - final MapsObjectId id2 = - MapsObjectId('2'); - final MapsObjectId id3 = - MapsObjectId('3'); + final MapsObjectId id1 = MapsObjectId('1'); + final MapsObjectId id2 = MapsObjectId('2'); + final MapsObjectId id3 = MapsObjectId('3'); final TestMapsObject object1 = TestMapsObject(id1); final TestMapsObject object2 = TestMapsObject(id2, data: 2); final TestMapsObject object3 = TestMapsObject(id3); expect( serializeMapsObjectSet({object1, object2, object3}), - >[{'id': '1'}, {'id': '2'}, {'id': '3'}]); + >[ + {'id': '1'}, + {'id': '2'}, + {'id': '3'} + ]); }); } From d89c5ad88f7a1cb6f1808771d1fb7a0d414cd95e Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 12 Feb 2021 15:31:54 -0500 Subject: [PATCH 10/14] Address review feedback --- .../method_channel_google_maps_flutter.dart | 122 +----------------- .../google_maps_flutter_platform.dart | 6 +- .../lib/src/types/bitmap.dart | 65 +++++----- .../lib/src/types/camera.dart | 34 ++--- .../lib/src/types/cap.dart | 12 +- .../lib/src/types/circle.dart | 4 +- .../lib/src/types/location.dart | 6 +- .../lib/src/types/maps_object.dart | 4 +- .../lib/src/types/maps_object_updates.dart | 20 +-- .../lib/src/types/marker.dart | 15 +-- .../lib/src/types/pattern_item.dart | 10 +- .../lib/src/types/polygon.dart | 14 +- .../lib/src/types/polyline.dart | 12 +- .../lib/src/types/screen_coordinate.dart | 2 +- .../lib/src/types/tile.dart | 4 +- .../lib/src/types/tile_overlay.dart | 4 +- .../lib/src/types/tile_overlay_updates.dart | 2 +- .../lib/src/types/ui.dart | 12 +- .../lib/src/types/utils/circle.dart | 2 +- .../lib/src/types/utils/maps_object.dart | 6 +- .../lib/src/types/utils/marker.dart | 2 +- .../lib/src/types/utils/polygon.dart | 2 +- .../lib/src/types/utils/polyline.dart | 2 +- .../lib/src/types/utils/tile_overlay.dart | 3 +- .../test/types/maps_object_test.dart | 2 +- .../test/types/maps_object_updates_test.dart | 10 +- .../test/types/test_maps_object.dart | 4 +- .../test/types/tile_overlay_test.dart | 18 +-- .../test/types/tile_overlay_updates_test.dart | 10 +- .../test/types/tile_test.dart | 19 +-- 30 files changed, 157 insertions(+), 271 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index 3f2f08e2e4d7..d644e12d83e1 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -58,9 +58,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { // Keep a collection of mapId to a map of TileOverlays. final Map> _tileOverlays = {}; - /// Initializes the platform interface with [id]. - /// - /// This method is called when the plugin is first initialized. @override Future init(int mapId) { MethodChannel? channel = _channels[mapId]; @@ -73,9 +70,8 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { return channel.invokeMethod('map#waitForMap'); } - /// Dispose of the native resources. @override - void dispose({int? mapId}) { + void dispose({required mapId}) { // Noop! } @@ -230,12 +226,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { } } - /// Updates configuration options of the map user interface. - /// - /// Change listeners are notified once the update has been made on the - /// platform side. - /// - /// The returned [Future] completes after listeners have been notified. @override Future updateMapOptions( Map optionsUpdate, { @@ -250,12 +240,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { ); } - /// Updates marker configuration. - /// - /// Change listeners are notified once the update has been made on the - /// platform side. - /// - /// The returned [Future] completes after listeners have been notified. @override Future updateMarkers( MarkerUpdates markerUpdates, { @@ -268,12 +252,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { ); } - /// Updates polygon configuration. - /// - /// Change listeners are notified once the update has been made on the - /// platform side. - /// - /// The returned [Future] completes after listeners have been notified. @override Future updatePolygons( PolygonUpdates polygonUpdates, { @@ -286,12 +264,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { ); } - /// Updates polyline configuration. - /// - /// Change listeners are notified once the update has been made on the - /// platform side. - /// - /// The returned [Future] completes after listeners have been notified. @override Future updatePolylines( PolylineUpdates polylineUpdates, { @@ -304,12 +276,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { ); } - /// Updates circle configuration. - /// - /// Change listeners are notified once the update has been made on the - /// platform side. - /// - /// The returned [Future] completes after listeners have been notified. @override Future updateCircles( CircleUpdates circleUpdates, { @@ -322,14 +288,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { ); } - /// Updates tile overlay configuration. - /// - /// Change listeners are notified once the update has been made on the - /// platform side. - /// - /// The returned [Future] completes after listeners have been notified. - /// - /// If `newTileOverlays` is null, all the [TileOverlays] are removed for the Map with `mapId`. @override Future updateTileOverlays({ required Set newTileOverlays, @@ -337,8 +295,9 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { }) { final Map? currentTileOverlays = _tileOverlays[mapId]; - Set? previousSet = - currentTileOverlays != null ? currentTileOverlays.values.toSet() : null; + Set previousSet = currentTileOverlays != null + ? currentTileOverlays.values.toSet() + : {}; final TileOverlayUpdates updates = TileOverlayUpdates.from(previousSet, newTileOverlays); _tileOverlays[mapId] = keyTileOverlayId(newTileOverlays); @@ -348,43 +307,27 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { ); } - /// Clears the tile cache so that all tiles will be requested again from the - /// [TileProvider]. - /// - /// The current tiles from this tile overlay will also be - /// cleared from the map after calling this method. The Google Map SDK maintains a small - /// in-memory cache of tiles. If you want to cache tiles for longer, you - /// should implement an on-disk cache. @override Future clearTileCache( TileOverlayId tileOverlayId, { required int mapId, }) { return channel(mapId) - .invokeMethod('tileOverlays#clearTileCache', { + .invokeMethod('tileOverlays#clearTileCache', { 'tileOverlayId': tileOverlayId.value, }); } - /// Starts an animated change of the map camera position. - /// - /// The returned [Future] completes after the change has been started on the - /// platform side. @override Future animateCamera( CameraUpdate cameraUpdate, { required int mapId, }) { - return channel(mapId) - .invokeMethod('camera#animate', { + return channel(mapId).invokeMethod('camera#animate', { 'cameraUpdate': cameraUpdate.toJson(), }); } - /// Changes the map camera position. - /// - /// The returned [Future] completes after the change has been made on the - /// platform side. @override Future moveCamera( CameraUpdate cameraUpdate, { @@ -395,19 +338,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { }); } - /// Sets the styling of the base map. - /// - /// Set to `null` to clear any previous custom styling. - /// - /// If problems were detected with the [mapStyle], including un-parsable - /// styling JSON, unrecognized feature type, unrecognized element type, or - /// invalid styler keys: [MapStyleException] is thrown and the current - /// style is left unchanged. - /// - /// The style string can be generated using [map style tool](https://mapstyle.withgoogle.com/). - /// Also, refer [iOS](https://developers.google.com/maps/documentation/ios-sdk/style-reference) - /// and [Android](https://developers.google.com/maps/documentation/android-sdk/style-reference) - /// style reference for more information regarding the supported styles. @override Future setMapStyle( String? mapStyle, { @@ -421,7 +351,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { } } - /// Return the region that is visible in a map. @override Future getVisibleRegion({ required int mapId, @@ -434,11 +363,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { return LatLngBounds(northeast: northeast, southwest: southwest); } - /// Return point [Map] of the [screenCoordinateInJson] in the current map view. - /// - /// A projection is used to translate between on screen location and geographic coordinates. - /// Screen location is in screen pixels (not display pixels) with respect to the top left corner - /// of the map, not necessarily of the whole screen. @override Future getScreenCoordinate( LatLng latLng, { @@ -451,10 +375,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { return ScreenCoordinate(x: point['x']!, y: point['y']!); } - /// Returns [LatLng] corresponding to the [ScreenCoordinate] in the current map view. - /// - /// Returned [LatLng] corresponds to a screen location. The screen location is specified in screen - /// pixels (not display pixels) relative to the top left of the map, not top left of the whole screen. @override Future getLatLng( ScreenCoordinate screenCoordinate, { @@ -466,14 +386,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { return LatLng(latLng[0], latLng[1]); } - /// Programmatically show the Info Window for a [Marker]. - /// - /// The `markerId` must match one of the markers on the map. - /// An invalid `markerId` triggers an "Invalid markerId" error. - /// - /// * See also: - /// * [hideMarkerInfoWindow] to hide the Info Window. - /// * [isMarkerInfoWindowShown] to check if the Info Window is showing. @override Future showMarkerInfoWindow( MarkerId markerId, { @@ -484,14 +396,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { 'markers#showInfoWindow', {'markerId': markerId.value}); } - /// Programmatically hide the Info Window for a [Marker]. - /// - /// The `markerId` must match one of the markers on the map. - /// An invalid `markerId` triggers an "Invalid markerId" error. - /// - /// * See also: - /// * [showMarkerInfoWindow] to show the Info Window. - /// * [isMarkerInfoWindowShown] to check if the Info Window is showing. @override Future hideMarkerInfoWindow( MarkerId markerId, { @@ -502,14 +406,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { 'markers#hideInfoWindow', {'markerId': markerId.value}); } - /// Returns `true` when the [InfoWindow] is showing, `false` otherwise. - /// - /// The `markerId` must match one of the markers on the map. - /// An invalid `markerId` triggers an "Invalid markerId" error. - /// - /// * See also: - /// * [showMarkerInfoWindow] to show the Info Window. - /// * [hideMarkerInfoWindow] to hide the Info Window. @override Future isMarkerInfoWindowShown( MarkerId markerId, { @@ -520,7 +416,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { {'markerId': markerId.value}) as Future; } - /// Returns the current zoom level of the map @override Future getZoomLevel({ required int mapId, @@ -529,7 +424,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { as Future; } - /// Returns the image bytes of the map @override Future takeSnapshot({ required int mapId, @@ -537,10 +431,6 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { return channel(mapId).invokeMethod('map#takeSnapshot'); } - /// This method builds the appropriate platform view where the map - /// can be rendered. - /// The `mapId` is passed as a parameter from the framework on the - /// `onPlatformViewCreated` callback. @override Widget buildView( Map creationParams, diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart index 6baaf6c38864..31b64d1a3f8c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart @@ -259,14 +259,16 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { throw UnimplementedError('updateMapOptions() has not been implemented.'); } - /// Returns the current zoom level of the map + /// Returns the current zoom level of the map. Future getZoomLevel({ required int mapId, }) { throw UnimplementedError('getZoomLevel() has not been implemented.'); } - /// Returns the image bytes of the map + /// Returns the image bytes of the map. + /// + /// Returns null if a snapshot cannot be created. Future takeSnapshot({ required int mapId, }) { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart index ce417e972e40..cc9887512d0e 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart @@ -62,14 +62,14 @@ class BitmapDescriptor { /// Creates a BitmapDescriptor that refers to the default marker image. static const BitmapDescriptor defaultMarker = - BitmapDescriptor._([_defaultMarker]); + BitmapDescriptor._([_defaultMarker]); /// Creates a BitmapDescriptor that refers to a colorization of the default /// marker image. For convenience, there is a predefined set of hue values. /// See e.g. [hueYellow]. static BitmapDescriptor defaultMarkerWithHue(double hue) { assert(0.0 <= hue && hue < 360.0); - return BitmapDescriptor._([_defaultMarker, hue]); + return BitmapDescriptor._([_defaultMarker, hue]); } /// Creates a [BitmapDescriptor] from an asset image. @@ -86,11 +86,12 @@ class BitmapDescriptor { String? package, bool mipmaps = true, }) async { - if (!mipmaps && configuration.devicePixelRatio != null) { - return BitmapDescriptor._([ + double? devicePixelRatio = configuration.devicePixelRatio; + if (!mipmaps && devicePixelRatio != null) { + return BitmapDescriptor._([ _fromAssetImage, assetName, - configuration.devicePixelRatio, + devicePixelRatio, ]); } final AssetImage assetImage = @@ -98,7 +99,7 @@ class BitmapDescriptor { final AssetBundleImageKey assetBundleImageKey = await assetImage.obtainKey(configuration); final Size? size = configuration.size; - return BitmapDescriptor._([ + return BitmapDescriptor._([ _fromAssetImage, assetBundleImageKey.name, assetBundleImageKey.scale, @@ -113,7 +114,7 @@ class BitmapDescriptor { /// Creates a BitmapDescriptor using an array of bytes that must be encoded /// as PNG. static BitmapDescriptor fromBytes(Uint8List byteData) { - return BitmapDescriptor._([_fromBytes, byteData]); + return BitmapDescriptor._([_fromBytes, byteData]); } /// The inverse of .toJson. @@ -121,37 +122,39 @@ class BitmapDescriptor { // transformed to JSON for transport. // TODO(https://github.com/flutter/flutter/issues/70330): Clean this up. BitmapDescriptor.fromJson(Object json) : _json = json { - assert(_validTypes.contains(_json[0])); - switch (_json[0]) { + assert(_json is List); + final jsonList = json as List; + assert(_validTypes.contains(jsonList[0])); + switch (jsonList[0]) { case _defaultMarker: - assert(_json.length <= 2); - if (_json.length == 2) { - assert(_json[1] is num); - assert(0 <= _json[1] && _json[1] < 360); + assert(jsonList.length <= 2); + if (jsonList.length == 2) { + assert(jsonList[1] is num); + assert(0 <= jsonList[1] && jsonList[1] < 360); } break; case _fromBytes: - assert(_json.length == 2); - assert(_json[1] != null && _json[1] is List); - assert((_json[1] as List).isNotEmpty); + assert(jsonList.length == 2); + assert(jsonList[1] != null && jsonList[1] is List); + assert((jsonList[1] as List).isNotEmpty); break; case _fromAsset: - assert(_json.length <= 3); - assert(_json[1] != null && _json[1] is String); - assert((_json[1] as String).isNotEmpty); - if (_json.length == 3) { - assert(_json[2] != null && _json[2] is String); - assert((_json[2] as String).isNotEmpty); + assert(jsonList.length <= 3); + assert(jsonList[1] != null && jsonList[1] is String); + assert((jsonList[1] as String).isNotEmpty); + if (jsonList.length == 3) { + assert(jsonList[2] != null && jsonList[2] is String); + assert((jsonList[2] as String).isNotEmpty); } break; case _fromAssetImage: - assert(_json.length <= 4); - assert(_json[1] != null && _json[1] is String); - assert((_json[1] as String).isNotEmpty); - assert(_json[2] != null && _json[2] is double); - if (_json.length == 4) { - assert(_json[3] != null && _json[3] is List); - assert((_json[3] as List).length == 2); + assert(jsonList.length <= 4); + assert(jsonList[1] != null && jsonList[1] is String); + assert((jsonList[1] as String).isNotEmpty); + assert(jsonList[2] != null && jsonList[2] is double); + if (jsonList.length == 4) { + assert(jsonList[3] != null && jsonList[3] is List); + assert((jsonList[3] as List).length == 2); } break; default: @@ -159,8 +162,8 @@ class BitmapDescriptor { } } - final dynamic _json; + final Object _json; /// Convert the object to a Json format. - dynamic toJson() => _json; + Object toJson() => _json; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart index 2f9caeb66ff4..bdb039572624 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart @@ -61,7 +61,7 @@ class CameraPosition { /// Serializes [CameraPosition]. /// /// Mainly for internal use when calling [CameraUpdate.newCameraPosition]. - dynamic toMap() => { + Object toMap() => { 'bearing': bearing, 'target': target.toJson(), 'tilt': tilt, @@ -71,8 +71,8 @@ class CameraPosition { /// Deserializes [CameraPosition] from a map. /// /// Mainly for internal use. - static CameraPosition? fromMap(dynamic json) { - if (json == null) { + static CameraPosition? fromMap(Object? json) { + if (json == null || !(json is Map)) { return null; } final LatLng? target = LatLng.fromJson(json['target']); @@ -88,10 +88,10 @@ class CameraPosition { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { if (identical(this, other)) return true; if (runtimeType != other.runtimeType) return false; - final CameraPosition typedOther = other; + final CameraPosition typedOther = other as CameraPosition; return bearing == typedOther.bearing && target == typedOther.target && tilt == typedOther.tilt && @@ -114,14 +114,14 @@ class CameraUpdate { /// Returns a camera update that moves the camera to the specified position. static CameraUpdate newCameraPosition(CameraPosition cameraPosition) { return CameraUpdate._( - ['newCameraPosition', cameraPosition.toMap()], + ['newCameraPosition', cameraPosition.toMap()], ); } /// Returns a camera update that moves the camera target to the specified /// geographical location. static CameraUpdate newLatLng(LatLng latLng) { - return CameraUpdate._(['newLatLng', latLng.toJson()]); + return CameraUpdate._(['newLatLng', latLng.toJson()]); } /// Returns a camera update that transforms the camera so that the specified @@ -129,7 +129,7 @@ class CameraUpdate { /// possible zoom level. A non-zero [padding] insets the bounding box from the /// map view's edges. The camera's new tilt and bearing will both be 0.0. static CameraUpdate newLatLngBounds(LatLngBounds bounds, double padding) { - return CameraUpdate._([ + return CameraUpdate._([ 'newLatLngBounds', bounds.toJson(), padding, @@ -140,7 +140,7 @@ class CameraUpdate { /// geographical location and zoom level. static CameraUpdate newLatLngZoom(LatLng latLng, double zoom) { return CameraUpdate._( - ['newLatLngZoom', latLng.toJson(), zoom], + ['newLatLngZoom', latLng.toJson(), zoom], ); } @@ -152,7 +152,7 @@ class CameraUpdate { /// 75 to the south of the current location, measured in screen coordinates. static CameraUpdate scrollBy(double dx, double dy) { return CameraUpdate._( - ['scrollBy', dx, dy], + ['scrollBy', dx, dy], ); } @@ -161,9 +161,9 @@ class CameraUpdate { /// geographical location should be invariant, if possible, by the movement. static CameraUpdate zoomBy(double amount, [Offset? focus]) { if (focus == null) { - return CameraUpdate._(['zoomBy', amount]); + return CameraUpdate._(['zoomBy', amount]); } else { - return CameraUpdate._([ + return CameraUpdate._([ 'zoomBy', amount, [focus.dx, focus.dy], @@ -176,7 +176,7 @@ class CameraUpdate { /// /// Equivalent to the result of calling `zoomBy(1.0)`. static CameraUpdate zoomIn() { - return CameraUpdate._(['zoomIn']); + return CameraUpdate._(['zoomIn']); } /// Returns a camera update that zooms the camera out, bringing the camera @@ -184,16 +184,16 @@ class CameraUpdate { /// /// Equivalent to the result of calling `zoomBy(-1.0)`. static CameraUpdate zoomOut() { - return CameraUpdate._(['zoomOut']); + return CameraUpdate._(['zoomOut']); } /// Returns a camera update that sets the camera zoom level. static CameraUpdate zoomTo(double zoom) { - return CameraUpdate._(['zoomTo', zoom]); + return CameraUpdate._(['zoomTo', zoom]); } - final dynamic _json; + final Object _json; /// Converts this object to something serializable in JSON. - dynamic toJson() => _json; + Object toJson() => _json; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart index 68bf14c36408..c88923a59404 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart @@ -17,16 +17,16 @@ class Cap { /// /// This is the default cap type at start and end vertices of Polylines with /// solid stroke pattern. - static const Cap buttCap = Cap._(['buttCap']); + static const Cap buttCap = Cap._(['buttCap']); /// Cap that is a semicircle with radius equal to half the stroke width, /// centered at the start or end vertex of a [Polyline] with solid stroke /// pattern. - static const Cap roundCap = Cap._(['roundCap']); + static const Cap roundCap = Cap._(['roundCap']); /// Cap that is squared off after extending half the stroke width beyond the /// start or end vertex of a [Polyline] with solid stroke pattern. - static const Cap squareCap = Cap._(['squareCap']); + static const Cap squareCap = Cap._(['squareCap']); /// Constructs a new CustomCap with a bitmap overlay centered at the start or /// end vertex of a [Polyline], orientated according to the direction of the line's @@ -45,11 +45,11 @@ class Cap { }) { assert(bitmapDescriptor != null); assert(refWidth > 0.0); - return Cap._(['customCap', bitmapDescriptor.toJson(), refWidth]); + return Cap._(['customCap', bitmapDescriptor.toJson(), refWidth]); } - final dynamic _json; + final Object _json; /// Converts this object to something serializable in JSON. - dynamic toJson() => _json; + Object toJson() => _json; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart index 21fe61328d70..e3198dfd6512 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart @@ -108,8 +108,8 @@ class Circle implements MapsObject { Circle clone() => copyWith(); /// Converts this object to something serializable in JSON. - dynamic toJson() { - final Map json = {}; + Object toJson() { + final Map json = {}; void addIfPresent(String fieldName, Object? value) { if (value != null) { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart index b77b7517df3c..a719f0bc741f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/location.dart @@ -29,7 +29,7 @@ class LatLng { final double longitude; /// Converts this object to something serializable in JSON. - dynamic toJson() { + Object toJson() { return [latitude, longitude]; } @@ -80,8 +80,8 @@ class LatLngBounds { final LatLng northeast; /// Converts this object to something serializable in JSON. - dynamic toJson() { - return [southwest.toJson(), northeast.toJson()]; + Object toJson() { + return [southwest.toJson(), northeast.toJson()]; } /// Returns whether this rectangle contains the given [LatLng]. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart index 1023cbfb8165..545d46272215 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart @@ -32,7 +32,7 @@ class MapsObjectId { @override String toString() { - return '${objectRuntimeType(this, 'MapsObjectId')}{value: $value}'; + return '${objectRuntimeType(this, 'MapsObjectId')}($value)'; } } @@ -45,5 +45,5 @@ abstract class MapsObject { T clone(); /// Converts this object to something serializable in JSON. - dynamic toJson(); + Object toJson(); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart index 6c88afab3882..01cf967f54e3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object_updates.dart @@ -17,18 +17,10 @@ class MapsObjectUpdates { /// dictionary. E.g., 'circle' will give 'circlesToAdd', 'circlesToUpdate', /// 'circleIdsToRemove'. MapsObjectUpdates.from( - Set? previous, + Set previous, Set current, { required this.objectName, }) { - if (previous == null) { - previous = Set.identity(); - } - - if (current == null) { - current = Set.identity(); - } - final Map, T> previousObjects = keyByMapsObjectId(previous); final Map, T> currentObjects = keyByMapsObjectId(current); @@ -89,8 +81,8 @@ class MapsObjectUpdates { late Set _objectsToChange; /// Converts this object to JSON. - Map toJson() { - final Map updateMap = {}; + Object toJson() { + final Map updateMap = {}; void addIfNonNull(String fieldName, Object? value) { if (value != null) { @@ -104,7 +96,7 @@ class MapsObjectUpdates { addIfNonNull( '${objectName}IdsToRemove', _objectIdsToRemove - .map((MapsObjectId m) => m.value) + .map((MapsObjectId m) => m.value) .toList()); return updateMap; @@ -127,8 +119,8 @@ class MapsObjectUpdates { @override String toString() { - return '${objectRuntimeType(this, 'MapsObjectUpdates')}{add: $objectsToAdd, ' + return '${objectRuntimeType(this, 'MapsObjectUpdates')}(add: $objectsToAdd, ' 'remove: $objectIdsToRemove, ' - 'change: $objectsToChange}'; + 'change: $objectsToChange)'; } } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart index 15d7269420d2..15351d58168b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart @@ -9,11 +9,8 @@ import 'package:meta/meta.dart' show immutable; import 'types.dart'; -dynamic _offsetToJson(Offset offset) { - if (offset == null) { - return null; - } - return [offset.dx, offset.dy]; +Object _offsetToJson(Offset offset) { + return [offset.dx, offset.dy]; } /// Text labels for a [Marker] info window. @@ -66,8 +63,8 @@ class InfoWindow { ); } - dynamic _toJson() { - final Map json = {}; + Object _toJson() { + final Map json = {}; void addIfPresent(String fieldName, Object? value) { if (value != null) { @@ -252,8 +249,8 @@ class Marker implements MapsObject { Marker clone() => copyWith(); /// Converts this object to something serializable in JSON. - Map toJson() { - final Map json = {}; + Object toJson() { + final Map json = {}; void addIfPresent(String fieldName, Object? value) { if (value != null) { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index 28c7ce9d33dd..f1cd7f4cb8eb 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -10,14 +10,14 @@ class PatternItem { const PatternItem._(this._json); /// A dot used in the stroke pattern for a [Polyline]. - static const PatternItem dot = PatternItem._(['dot']); + static const PatternItem dot = PatternItem._(['dot']); /// A dash used in the stroke pattern for a [Polyline]. /// /// [length] has to be non-negative. static PatternItem dash(double length) { assert(length >= 0.0); - return PatternItem._(['dash', length]); + return PatternItem._(['dash', length]); } /// A gap used in the stroke pattern for a [Polyline]. @@ -25,11 +25,11 @@ class PatternItem { /// [length] has to be non-negative. static PatternItem gap(double length) { assert(length >= 0.0); - return PatternItem._(['gap', length]); + return PatternItem._(['gap', length]); } - final dynamic _json; + final Object _json; /// Converts this object to something serializable in JSON. - dynamic toJson() => _json; + Object toJson() => _json; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart index 13ac417c7a55..4e5e9bf13d84 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart @@ -128,8 +128,8 @@ class Polygon implements MapsObject { } /// Converts this object to something serializable in JSON. - dynamic toJson() { - final Map json = {}; + Object toJson() { + final Map json = {}; void addIfPresent(String fieldName, Object? value) { if (value != null) { @@ -177,18 +177,18 @@ class Polygon implements MapsObject { @override int get hashCode => polygonId.hashCode; - dynamic _pointsToJson() { - final List result = []; + Object _pointsToJson() { + final List result = []; for (final LatLng point in points) { result.add(point.toJson()); } return result; } - List> _holesToJson() { - final List> result = >[]; + List> _holesToJson() { + final List> result = >[]; for (final List hole in holes) { - final List jsonHole = []; + final List jsonHole = []; for (final LatLng point in hole) { jsonHole.add(point.toJson()); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart index 5f6d874f885f..3f87395164f6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart @@ -158,8 +158,8 @@ class Polyline implements MapsObject { } /// Converts this object to something serializable in JSON. - dynamic toJson() { - final Map json = {}; + Object toJson() { + final Map json = {}; void addIfPresent(String fieldName, Object? value) { if (value != null) { @@ -211,16 +211,16 @@ class Polyline implements MapsObject { @override int get hashCode => polylineId.hashCode; - dynamic _pointsToJson() { - final List result = []; + Object _pointsToJson() { + final List result = []; for (final LatLng point in points) { result.add(point.toJson()); } return result; } - dynamic _patternToJson() { - final List result = []; + Object _patternToJson() { + final List result = []; for (final PatternItem patternItem in patterns) { if (patternItem != null) { result.add(patternItem.toJson()); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart index dc4e72bc358d..af7a951a149c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/screen_coordinate.dart @@ -26,7 +26,7 @@ class ScreenCoordinate { final int y; /// Converts this object to something serializable in JSON. - dynamic toJson() { + Object toJson() { return { "x": x, "y": y, diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart index 1f4bdbc02ab6..bfc322856b5a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile.dart @@ -24,8 +24,8 @@ class Tile { final Uint8List? data; /// Converts this object to JSON. - Map toJson() { - final Map json = {}; + Object toJson() { + final Map json = {}; void addIfPresent(String fieldName, Object? value) { if (value != null) { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart index d07581bd187e..e31bfb461fb4 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart @@ -109,8 +109,8 @@ class TileOverlay implements MapsObject { TileOverlay clone() => copyWith(); /// Converts this object to JSON. - Map toJson() { - final Map json = {}; + Object toJson() { + final Map json = {}; void addIfPresent(String fieldName, Object? value) { if (value != null) { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart index 02b96bf4bd34..1436880e9626 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay_updates.dart @@ -7,7 +7,7 @@ import 'types.dart'; /// Update specification for a set of [TileOverlay]s. class TileOverlayUpdates extends MapsObjectUpdates { /// Computes [TileOverlayUpdates] given previous and current [TileOverlay]s. - TileOverlayUpdates.from(Set? previous, Set current) + TileOverlayUpdates.from(Set previous, Set current) : super.from(previous, current, objectName: 'tileOverlay'); /// Set of TileOverlays to be added in this update. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/ui.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/ui.dart index f56acf19ec06..1c030e338353 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/ui.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/ui.dart @@ -45,13 +45,13 @@ class CameraTargetBounds { static const CameraTargetBounds unbounded = CameraTargetBounds(null); /// Converts this object to something serializable in JSON. - dynamic toJson() => [bounds?.toJson()]; + Object toJson() => [bounds?.toJson()]; @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { if (identical(this, other)) return true; if (runtimeType != other.runtimeType) return false; - final CameraTargetBounds typedOther = other; + final CameraTargetBounds typedOther = other as CameraTargetBounds; return bounds == typedOther.bounds; } @@ -86,13 +86,13 @@ class MinMaxZoomPreference { MinMaxZoomPreference(null, null); /// Converts this object to something serializable in JSON. - dynamic toJson() => [minZoom, maxZoom]; + Object toJson() => [minZoom, maxZoom]; @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { if (identical(this, other)) return true; if (runtimeType != other.runtimeType) return false; - final MinMaxZoomPreference typedOther = other; + final MinMaxZoomPreference typedOther = other as MinMaxZoomPreference; return minZoom == typedOther.minZoom && maxZoom == typedOther.maxZoom; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart index 6d716a7de915..18bd31ec7df6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/circle.dart @@ -11,6 +11,6 @@ Map keyByCircleId(Iterable circles) { } /// Converts a Set of Circles into something serializable in JSON. -List>? serializeCircleSet(Set circles) { +Object serializeCircleSet(Set circles) { return serializeMapsObjectSet(circles); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart index 3b0988dffd13..fa5a7e7591ee 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/maps_object.dart @@ -13,8 +13,6 @@ Map, T> keyByMapsObjectId( } /// Converts a Set of [MapsObject]s into something serializable in JSON. -List> serializeMapsObjectSet(Set mapsObjects) { - return mapsObjects - .map>((MapsObject p) => p.toJson()) - .toList(); +Object serializeMapsObjectSet(Set mapsObjects) { + return mapsObjects.map((MapsObject p) => p.toJson()).toList(); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart index 72c0d878bdc5..057bebdc8b8a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/marker.dart @@ -11,6 +11,6 @@ Map keyByMarkerId(Iterable markers) { } /// Converts a Set of Markers into something serializable in JSON. -List>? serializeMarkerSet(Set markers) { +Object serializeMarkerSet(Set markers) { return serializeMapsObjectSet(markers); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart index 4bce47b56b1d..050ecafce31f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polygon.dart @@ -11,6 +11,6 @@ Map keyByPolygonId(Iterable polygons) { } /// Converts a Set of Polygons into something serializable in JSON. -List>? serializePolygonSet(Set polygons) { +Object serializePolygonSet(Set polygons) { return serializeMapsObjectSet(polygons); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart index 380747107e59..8f4098feedf7 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/polyline.dart @@ -11,6 +11,6 @@ Map keyByPolylineId(Iterable polylines) { } /// Converts a Set of Polylines into something serializable in JSON. -List>? serializePolylineSet(Set polylines) { +Object serializePolylineSet(Set polylines) { return serializeMapsObjectSet(polylines); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart index 5a80612c0648..336f814d329a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/tile_overlay.dart @@ -13,7 +13,6 @@ Map keyTileOverlayId( } /// Converts a Set of TileOverlays into something serializable in JSON. -List>? serializeTileOverlaySet( - Set tileOverlays) { +Object serializeTileOverlaySet(Set tileOverlays) { return serializeMapsObjectSet(tileOverlays); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart index 5d9878bc588c..65692bd2a385 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart @@ -36,7 +36,7 @@ void main() { final TestMapsObject object3 = TestMapsObject(id3); expect( serializeMapsObjectSet({object1, object2, object3}), - >[ + >[ {'id': '1'}, {'id': '2'}, {'id': '3'} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_updates_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_updates_test.dart index 82039037bc3b..68f4c587c2f2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_updates_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_updates_test.dart @@ -70,12 +70,12 @@ void main() { final TestMapsObjectUpdate updates = TestMapsObjectUpdate.from(previous, current); - final Map json = updates.toJson(); - expect(json, { + final Object json = updates.toJson(); + expect(json, { 'testObjectsToAdd': serializeMapsObjectSet(updates.objectsToAdd), 'testObjectsToChange': serializeMapsObjectSet(updates.objectsToChange), 'testObjectIdsToRemove': updates.objectIdsToRemove - .map((MapsObjectId m) => m.value) + .map((MapsObjectId m) => m.value) .toList() }); }); @@ -152,9 +152,9 @@ void main() { TestMapsObjectUpdate.from(previous, current); expect( updates.toString(), - 'TestMapsObjectUpdate{add: ${updates.objectsToAdd}, ' + 'TestMapsObjectUpdate(add: ${updates.objectsToAdd}, ' 'remove: ${updates.objectIdsToRemove}, ' - 'change: ${updates.objectsToChange}}'); + 'change: ${updates.objectsToChange})'); }); }); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/test_maps_object.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/test_maps_object.dart index 896631e94605..e15c73f08a54 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/test_maps_object.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/test_maps_object.dart @@ -21,8 +21,8 @@ class TestMapsObject implements MapsObject { } @override - dynamic toJson() { - return {'id': mapsId.value}; + Object toJson() { + return {'id': mapsId.value}; } @override diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_test.dart index c6254138c4d3..87380fdd651b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_test.dart @@ -20,7 +20,7 @@ void main() { test('toString', () async { final TileOverlayId id1 = TileOverlayId('1'); - expect(id1.toString(), 'TileOverlayId{value: 1}'); + expect(id1.toString(), 'TileOverlayId(1)'); }); }); @@ -34,13 +34,15 @@ void main() { zIndex: 1, visible: false, tileSize: 128); - final Map json = tileOverlay.toJson(); - expect(json['tileOverlayId'], 'id'); - expect(json['fadeIn'], false); - expect(json['transparency'], moreOrLessEquals(0.1)); - expect(json['zIndex'], 1); - expect(json['visible'], false); - expect(json['tileSize'], 128); + final Object json = tileOverlay.toJson(); + expect(json, { + 'tileOverlayId': 'id', + 'fadeIn': false, + 'transparency': moreOrLessEquals(0.1), + 'zIndex': 1, + 'visible': false, + 'tileSize': 128, + }); }); test('invalid transparency throws', () async { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_updates_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_updates_test.dart index 1d529088e460..f622ca5213ef 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_updates_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_overlay_updates_test.dart @@ -49,13 +49,13 @@ void main() { final TileOverlayUpdates updates = TileOverlayUpdates.from(previous, current); - final Map json = updates.toJson(); - expect(json, { + final Object json = updates.toJson(); + expect(json, { 'tileOverlaysToAdd': serializeTileOverlaySet(updates.tileOverlaysToAdd), 'tileOverlaysToChange': serializeTileOverlaySet(updates.tileOverlaysToChange), 'tileOverlayIdsToRemove': updates.tileOverlayIdsToRemove - .map((TileOverlayId m) => m.value) + .map((TileOverlayId m) => m.value) .toList() }); }); @@ -117,9 +117,9 @@ void main() { TileOverlayUpdates.from(previous, current); expect( updates.toString(), - 'TileOverlayUpdates{add: ${updates.tileOverlaysToAdd}, ' + 'TileOverlayUpdates(add: ${updates.tileOverlaysToAdd}, ' 'remove: ${updates.tileOverlayIdsToRemove}, ' - 'change: ${updates.tileOverlaysToChange}}'); + 'change: ${updates.tileOverlaysToChange})'); }); }); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_test.dart index 03ecd3c41a49..3e0fe99ec18c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/tile_test.dart @@ -13,18 +13,21 @@ void main() { test('toJson returns correct format', () async { final Uint8List data = Uint8List.fromList([0, 1]); final Tile tile = Tile(100, 200, data); - final Map json = tile.toJson(); - expect(json['width'], 100); - expect(json['height'], 200); - expect(json['data'], data); + final Object json = tile.toJson(); + expect(json, { + 'width': 100, + 'height': 200, + 'data': data, + }); }); test('toJson handles null data', () async { final Tile tile = Tile(0, 0, null); - final Map json = tile.toJson(); - expect(json['width'], 0); - expect(json['height'], 0); - expect(json['data'], isNull); + final Object json = tile.toJson(); + expect(json, { + 'width': 0, + 'height': 0, + }); }); }); } From e0b547dc52d29d40b674f10627045c06020a4874 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 12 Feb 2021 16:24:19 -0500 Subject: [PATCH 11/14] Review nits --- .../google_maps_flutter_platform_interface/CHANGELOG.md | 1 + script/nnbd_plugins.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md index 1043cfa4b2a2..8d00155977f9 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md @@ -1,6 +1,7 @@ ## 2.0.0-nullsafety * Migrated to null-safety. +* BREAKING CHANGE: Removed deprecated APIs. ## 1.2.0 diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 492c8adf3ad5..4d7dacbdfbae 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -38,7 +38,7 @@ readonly NNBD_PLUGINS_LIST=( readonly NON_NNBD_PLUGINS_LIST=( # "android_alarm_manager" "camera" - # "google_maps_flutter" + "google_maps_flutter" # "image_picker" # "in_app_purchase" # "quick_actions" From b8a875fcb230d692f041db022c1e292759f99db3 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 12 Feb 2021 16:37:23 -0500 Subject: [PATCH 12/14] Fix exclusion --- script/nnbd_plugins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 4d7dacbdfbae..82f12067e60e 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -14,6 +14,7 @@ readonly NNBD_PLUGINS_LIST=( "file_selector" "flutter_plugin_android_lifecycle" "flutter_webview" + "google_maps_flutter" "google_sign_in" "image_picker" "ios_platform_images" @@ -38,7 +39,6 @@ readonly NNBD_PLUGINS_LIST=( readonly NON_NNBD_PLUGINS_LIST=( # "android_alarm_manager" "camera" - "google_maps_flutter" # "image_picker" # "in_app_purchase" # "quick_actions" From 01985c844294d37e849241e01ae08f6216cbbcdc Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 12 Feb 2021 18:29:08 -0500 Subject: [PATCH 13/14] Exclude from both --- script/nnbd_plugins.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 82f12067e60e..3f6efa7b06a5 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -39,6 +39,7 @@ readonly NNBD_PLUGINS_LIST=( readonly NON_NNBD_PLUGINS_LIST=( # "android_alarm_manager" "camera" + "google_maps_flutter" # half migrated # "image_picker" # "in_app_purchase" # "quick_actions" From 2faa94c575dc7e05c792a073577ab549badc5569 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sun, 14 Feb 2021 13:04:21 -0500 Subject: [PATCH 14/14] Address last review comments --- .../CHANGELOG.md | 4 ++ .../method_channel_google_maps_flutter.dart | 41 ++++++++++++++----- .../google_maps_flutter_platform.dart | 17 ++++++-- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md index 8d00155977f9..c530c31e488d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md @@ -2,6 +2,10 @@ * Migrated to null-safety. * BREAKING CHANGE: Removed deprecated APIs. +* BREAKING CHANGE: Many sets in APIs that used to treat null and empty set as + equivalent now require passing an empty set. +* BREAKING CHANGE: toJson now always returns an `Object`; the details of the + object type and structure should be treated as an implementation detail. ## 1.2.0 diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index d644e12d83e1..3d16127ab7a9 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -17,17 +17,21 @@ import '../types/utils/tile_overlay.dart'; /// Error thrown when an unknown map ID is provided to a method channel API. class UnknownMapIDError extends Error { + /// Creates an assertion error with the provided [mapId] and optional + /// [message]. + UnknownMapIDError(this.mapId, [this.message]); + + /// The unknown ID. + final int mapId; + /// Message describing the assertion error. final Object? message; - /// Creates an assertion error with the provided [message]. - UnknownMapIDError([this.message]); - String toString() { if (message != null) { - return "Unknown map ID: ${Error.safeToString(message)}"; + return "Unknown map ID $mapId: ${Error.safeToString(message)}"; } - return "Unknown map ID"; + return "Unknown map ID $mapId"; } } @@ -50,7 +54,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { MethodChannel channel(int mapId) { MethodChannel? channel = _channels[mapId]; if (channel == null) { - throw UnknownMapIDError(); + throw UnknownMapIDError(mapId); } return channel; } @@ -71,7 +75,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { } @override - void dispose({required mapId}) { + void dispose({required int mapId}) { // Noop! } @@ -433,9 +437,26 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Widget buildView( - Map creationParams, - Set>? gestureRecognizers, - PlatformViewCreatedCallback onPlatformViewCreated) { + int creationId, + PlatformViewCreatedCallback onPlatformViewCreated, { + required CameraPosition initialCameraPosition, + Set markers = const {}, + Set polygons = const {}, + Set polylines = const {}, + Set circles = const {}, + Set tileOverlays = const {}, + Set>? gestureRecognizers, + Map mapOptions = const {}, + }) { + final Map creationParams = { + 'initialCameraPosition': initialCameraPosition.toMap(), + 'options': mapOptions, + 'markersToAdd': serializeMarkerSet(markers), + 'polygonsToAdd': serializePolygonSet(polygons), + 'polylinesToAdd': serializePolylineSet(polylines), + 'circlesToAdd': serializeCircleSet(circles), + 'tileOverlaysToAdd': serializeTileOverlaySet(tileOverlays), + }; if (defaultTargetPlatform == TargetPlatform.android) { return AndroidView( viewType: 'plugins.flutter.io/google_maps', diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart index 31b64d1a3f8c..a363fc30f83c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart @@ -340,9 +340,20 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { /// Returns a widget displaying the map view Widget buildView( - Map creationParams, - Set>? gestureRecognizers, - PlatformViewCreatedCallback onPlatformViewCreated) { + int creationId, + PlatformViewCreatedCallback onPlatformViewCreated, { + required CameraPosition initialCameraPosition, + Set markers = const {}, + Set polygons = const {}, + Set polylines = const {}, + Set circles = const {}, + Set tileOverlays = const {}, + Set>? gestureRecognizers = + const >{}, + // TODO: Replace with a structured type that's part of the interface. + // See https://github.com/flutter/flutter/issues/70330. + Map mapOptions = const {}, + }) { throw UnimplementedError('buildView() has not been implemented.'); } }