From 99aa799ea07ac717e9fc3205b22c7cb00cb528f3 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Mon, 23 May 2022 14:08:08 -0400 Subject: [PATCH] [google_maps_flutter] Updates platform interface to new analysis options (#5793) --- analysis_options.yaml | 4 - analysis_options_legacy.yaml | 14 --- .../CHANGELOG.md | 3 +- .../analysis_options.yaml | 1 - ...oogle_maps_flutter_platform_interface.dart | 2 +- .../lib/src/events/map_event.dart | 18 ++-- .../method_channel_google_maps_flutter.dart | 57 +++++----- .../google_maps_flutter_platform.dart | 11 +- .../lib/src/types/bitmap.dart | 101 +++++++++--------- .../lib/src/types/callbacks.dart | 6 +- .../lib/src/types/camera.dart | 29 +++-- .../lib/src/types/circle.dart | 32 +++--- .../lib/src/types/location.dart | 32 +++--- .../lib/src/types/maps_object.dart | 11 +- .../lib/src/types/maps_object_updates.dart | 14 +-- .../lib/src/types/marker.dart | 55 ++++++---- .../lib/src/types/polygon.dart | 34 +++--- .../lib/src/types/polyline.dart | 38 ++++--- .../lib/src/types/screen_coordinate.dart | 12 +-- .../lib/src/types/tile_overlay.dart | 6 +- .../lib/src/types/types.dart | 11 +- .../lib/src/types/ui.dart | 28 +++-- .../lib/src/types/utils/maps_object.dart | 9 +- .../pubspec.yaml | 2 +- ...thod_channel_google_maps_flutter_test.dart | 55 +++++----- .../google_maps_flutter_platform_test.dart | 8 +- .../test/types/bitmap_test.dart | 67 ++++++------ .../test/types/camera_test.dart | 9 +- .../test/types/location_test.dart | 30 +++--- .../test/types/maps_object_test.dart | 6 +- .../test/types/maps_object_updates_test.dart | 68 +++++++----- .../test/types/marker_test.dart | 70 ++++++------ .../test/types/test_maps_object.dart | 5 +- .../test/types/tile_overlay_test.dart | 12 +-- .../test/types/tile_overlay_updates_test.dart | 39 +++---- .../test/types/tile_test.dart | 2 +- script/configs/custom_analysis.yaml | 10 +- script/tool/CHANGELOG.md | 4 + script/tool/lib/src/analyze_command.dart | 8 +- script/tool/test/analyze_command_test.dart | 12 +++ 40 files changed, 505 insertions(+), 430 deletions(-) delete mode 100644 analysis_options_legacy.yaml delete mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml index 87f7d6f9840b..87515a471050 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,10 +2,6 @@ # with minimal changes for this repository. The goal is to move toward using a # shared set of analysis options as much as possible, and eventually a shared # file. -# -# Plugins that have not yet switched from the previous set of options have a -# local analysis_options.yaml that points to analysis_options_legacy.yaml -# instead. # Specify analysis options. # diff --git a/analysis_options_legacy.yaml b/analysis_options_legacy.yaml deleted file mode 100644 index da3c18071650..000000000000 --- a/analysis_options_legacy.yaml +++ /dev/null @@ -1,14 +0,0 @@ -include: package:pedantic/analysis_options.1.8.0.yaml -analyzer: - exclude: - # Ignore generated files - - '**/*.g.dart' - - 'lib/src/generated/*.dart' - - '**/*.mocks.dart' # Mockito @GenerateMocks - - '**/*.pigeon.dart' # Pigeon generated file - errors: - always_require_non_null_named_parameters: false # not needed with nnbd - unnecessary_null_comparison: false # Turned as long as nnbd mix-mode is supported. -linter: - rules: - - public_member_api_docs 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 b6e15d2ad14c..0359bab0b7c5 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,5 +1,6 @@ -## NEXT +## 2.1.7 +* Updates code for stricter analysis options. * Removes unnecessary imports. ## 2.1.6 diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/analysis_options.yaml b/packages/google_maps_flutter/google_maps_flutter_platform_interface/analysis_options.yaml deleted file mode 100644 index 5aeb4e7c5e21..000000000000 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: ../../../analysis_options_legacy.yaml diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/google_maps_flutter_platform_interface.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/google_maps_flutter_platform_interface.dart index 300700071102..b83eaf4fdfc7 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/google_maps_flutter_platform_interface.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/google_maps_flutter_platform_interface.dart @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +export 'src/events/map_event.dart'; export 'src/method_channel/method_channel_google_maps_flutter.dart' show MethodChannelGoogleMapsFlutter; export 'src/platform_interface/google_maps_flutter_platform.dart'; export 'src/types/types.dart'; -export 'src/events/map_event.dart'; 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 bb4124612be4..8759126d4b67 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 @@ -34,29 +34,29 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf /// events to access the `.position` property, rather than the more generic `.value` /// yielded from the latter. class MapEvent { - /// The ID of the Map this event is associated to. - final int mapId; - - /// The value wrapped by this event - final T value; - /// Build a Map Event, that relates a mapId with a given value. /// /// The `mapId` is the id of the map that triggered the event. /// `value` may be `null` in events that don't transport any meaningful data. MapEvent(this.mapId, this.value); + + /// The ID of the Map this event is associated to. + final int mapId; + + /// The value wrapped by this event + final T value; } /// A `MapEvent` associated to a `position`. class _PositionedMapEvent extends MapEvent { - /// The position where this event happened. - final LatLng position; - /// Build a Positioned MapEvent, that relates a mapId and a position with a value. /// /// The `mapId` is the id of the map that triggered the event. /// `value` may be `null` in events that don't transport any meaningful data. _PositionedMapEvent(int mapId, this.position, T value) : super(mapId, value); + + /// The position where this event happened. + final LatLng position; } // The following events are the ones exposed to the end user. They are semantic extensions 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 9c5cbf5a54f0..365da757e435 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 @@ -27,11 +27,12 @@ class UnknownMapIDError extends Error { /// Message describing the assertion error. final Object? message; + @override String toString() { if (message != null) { - return "Unknown map ID $mapId: ${Error.safeToString(message)}"; + return 'Unknown map ID $mapId: ${Error.safeToString(message)}'; } - return "Unknown map ID $mapId"; + return 'Unknown map ID $mapId'; } } @@ -48,11 +49,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]; + final MethodChannel? channel = _channels[mapId]; if (channel == null) { throw UnknownMapIDError(mapId); } @@ -60,7 +61,8 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { } // Keep a collection of mapId to a map of TileOverlays. - final Map> _tileOverlays = {}; + final Map> _tileOverlays = + >{}; /// Returns the channel for [mapId], creating it if it doesn't already exist. @visibleForTesting @@ -77,7 +79,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { @override Future init(int mapId) { - MethodChannel channel = ensureChannelInitialized(mapId); + final MethodChannel channel = ensureChannelInitialized(mapId); return channel.invokeMethod('map#waitForMap'); } @@ -91,12 +93,13 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { // // It is a `broadcast` because multiple controllers will connect to // different stream views of this Controller. - final StreamController _mapEventStreamController = - StreamController.broadcast(); + final StreamController> _mapEventStreamController = + StreamController>.broadcast(); // Returns a filtered view of the events in the _controller, by mapId. - Stream _events(int mapId) => - _mapEventStreamController.stream.where((event) => event.mapId == mapId); + Stream> _events(int mapId) => + _mapEventStreamController.stream + .where((MapEvent event) => event.mapId == mapId); @override Stream onCameraMoveStarted({required int mapId}) { @@ -180,52 +183,52 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { case 'marker#onTap': _mapEventStreamController.add(MarkerTapEvent( mapId, - MarkerId(call.arguments['markerId']), + MarkerId(call.arguments['markerId'] as String), )); break; case 'marker#onDragStart': _mapEventStreamController.add(MarkerDragStartEvent( mapId, LatLng.fromJson(call.arguments['position'])!, - MarkerId(call.arguments['markerId']), + MarkerId(call.arguments['markerId'] as String), )); break; case 'marker#onDrag': _mapEventStreamController.add(MarkerDragEvent( mapId, LatLng.fromJson(call.arguments['position'])!, - MarkerId(call.arguments['markerId']), + MarkerId(call.arguments['markerId'] as String), )); break; case 'marker#onDragEnd': _mapEventStreamController.add(MarkerDragEndEvent( mapId, LatLng.fromJson(call.arguments['position'])!, - MarkerId(call.arguments['markerId']), + MarkerId(call.arguments['markerId'] as String), )); break; case 'infoWindow#onTap': _mapEventStreamController.add(InfoWindowTapEvent( mapId, - MarkerId(call.arguments['markerId']), + MarkerId(call.arguments['markerId'] as String), )); break; case 'polyline#onTap': _mapEventStreamController.add(PolylineTapEvent( mapId, - PolylineId(call.arguments['polylineId']), + PolylineId(call.arguments['polylineId'] as String), )); break; case 'polygon#onTap': _mapEventStreamController.add(PolygonTapEvent( mapId, - PolygonId(call.arguments['polygonId']), + PolygonId(call.arguments['polygonId'] as String), )); break; case 'circle#onTap': _mapEventStreamController.add(CircleTapEvent( mapId, - CircleId(call.arguments['circleId']), + CircleId(call.arguments['circleId'] as String), )); break; case 'map#onTap': @@ -243,17 +246,17 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { case 'tileOverlay#getTile': final Map? tileOverlaysForThisMap = _tileOverlays[mapId]; - final String tileOverlayId = call.arguments['tileOverlayId']; + final String tileOverlayId = call.arguments['tileOverlayId'] as String; final TileOverlay? tileOverlay = tileOverlaysForThisMap?[TileOverlayId(tileOverlayId)]; - TileProvider? tileProvider = tileOverlay?.tileProvider; + final TileProvider? tileProvider = tileOverlay?.tileProvider; if (tileProvider == null) { return TileProvider.noTile.toJson(); } final Tile tile = await tileProvider.getTile( - call.arguments['x'], - call.arguments['y'], - call.arguments['zoom'], + call.arguments['x'] as int, + call.arguments['y'] as int, + call.arguments['zoom'] as int?, ); return tile.toJson(); default: @@ -330,7 +333,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { }) { final Map? currentTileOverlays = _tileOverlays[mapId]; - Set previousSet = currentTileOverlays != null + final Set previousSet = currentTileOverlays != null ? currentTileOverlays.values.toSet() : {}; final TileOverlayUpdates updates = @@ -380,9 +383,9 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { }) async { final List successAndError = (await channel(mapId) .invokeMethod>('map#setStyle', mapStyle))!; - final bool success = successAndError[0]; + final bool success = successAndError[0] as bool; if (!success) { - throw MapStyleException(successAndError[1]); + throw MapStyleException(successAndError[1] as String); } } @@ -418,7 +421,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { final List latLng = (await channel(mapId) .invokeMethod>( 'map#getLatLng', screenCoordinate.toJson()))!; - return LatLng(latLng[0], latLng[1]); + return LatLng(latLng[0] as double, latLng[1] as double); } @override 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 b6c7b8be692d..6386ed2523f2 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 @@ -5,12 +5,11 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:flutter/widgets.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; - +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; @@ -359,8 +358,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { 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. + // TODO(stuartmorgan): 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.'); 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 d3dc37e327fe..c43baf42db45 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 @@ -6,24 +6,70 @@ import 'dart:async' show Future; import 'dart:typed_data' show Uint8List; import 'dart:ui' show Size; +import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart' show ImageConfiguration, AssetImage, AssetBundleImageKey; import 'package:flutter/services.dart' show AssetBundle; -import 'package:flutter/foundation.dart' show kIsWeb; - /// Defines a bitmap image. For a marker, this class can be used to set the /// image of the marker icon. For a ground overlay, it can be used to set the /// image to place on the surface of the earth. class BitmapDescriptor { const BitmapDescriptor._(this._json); + /// The inverse of .toJson. + // This is needed in Web to re-hydrate BitmapDescriptors that have been + // transformed to JSON for transport. + // TODO(stuartmorgan): Clean this up. See + // https://github.com/flutter/flutter/issues/70330 + BitmapDescriptor.fromJson(Object json) : _json = json { + assert(_json is List); + final List jsonList = json as List; + assert(_validTypes.contains(jsonList[0])); + switch (jsonList[0]) { + case _defaultMarker: + assert(jsonList.length <= 2); + if (jsonList.length == 2) { + assert(jsonList[1] is num); + final num secondElement = jsonList[1] as num; + assert(0 <= secondElement && secondElement < 360); + } + break; + case _fromBytes: + assert(jsonList.length == 2); + assert(jsonList[1] != null && jsonList[1] is List); + assert((jsonList[1] as List).isNotEmpty); + break; + case _fromAsset: + 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(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: + break; + } + } + static const String _defaultMarker = 'defaultMarker'; static const String _fromAsset = 'fromAsset'; static const String _fromAssetImage = 'fromAssetImage'; static const String _fromBytes = 'fromBytes'; - static const Set _validTypes = { + static const Set _validTypes = { _defaultMarker, _fromAsset, _fromAssetImage, @@ -86,7 +132,7 @@ class BitmapDescriptor { String? package, bool mipmaps = true, }) async { - double? devicePixelRatio = configuration.devicePixelRatio; + final double? devicePixelRatio = configuration.devicePixelRatio; if (!mipmaps && devicePixelRatio != null) { return BitmapDescriptor._([ _fromAssetImage, @@ -104,7 +150,7 @@ class BitmapDescriptor { assetBundleImageKey.name, assetBundleImageKey.scale, if (kIsWeb && size != null) - [ + [ size.width, size.height, ], @@ -117,51 +163,6 @@ class BitmapDescriptor { return BitmapDescriptor._([_fromBytes, byteData]); } - /// The inverse of .toJson. - // 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(Object json) : _json = json { - assert(_json is List); - final jsonList = json as List; - assert(_validTypes.contains(jsonList[0])); - switch (jsonList[0]) { - case _defaultMarker: - assert(jsonList.length <= 2); - if (jsonList.length == 2) { - assert(jsonList[1] is num); - assert(0 <= jsonList[1] && jsonList[1] < 360); - } - break; - case _fromBytes: - assert(jsonList.length == 2); - assert(jsonList[1] != null && jsonList[1] is List); - assert((jsonList[1] as List).isNotEmpty); - break; - case _fromAsset: - 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(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: - break; - } - } - final Object _json; /// Convert the object to a Json format. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/callbacks.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/callbacks.dart index 3b484c1feb05..5d6af90290e0 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/callbacks.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/callbacks.dart @@ -10,10 +10,10 @@ import 'types.dart'; /// registers a camera movement. /// /// This is used in [GoogleMap.onCameraMove]. -typedef void CameraPositionCallback(CameraPosition position); +typedef CameraPositionCallback = void Function(CameraPosition position); /// Callback function taking a single argument. -typedef void ArgumentCallback(T argument); +typedef ArgumentCallback = void Function(T argument); /// Mutable collection of [ArgumentCallback] instances, itself an [ArgumentCallback]. /// @@ -35,7 +35,7 @@ class ArgumentCallbacks { if (length == 1) { _callbacks[0].call(argument); } else if (0 < length) { - for (ArgumentCallback callback + for (final ArgumentCallback callback in List>.from(_callbacks)) { callback(argument); } 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 89006eba6214..6d1ce164238b 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,12 +4,15 @@ import 'dart:ui' show Offset; +import 'package:flutter/foundation.dart'; + import 'types.dart'; /// The position of the map "camera", the view point from which the world is shown in the map view. /// /// Aggregates the camera's [target] geographical location, its [zoom] level, /// [tilt] angle, and [bearing]. +@immutable class CameraPosition { /// Creates a immutable representation of the [GoogleMap] camera. /// @@ -72,7 +75,7 @@ class CameraPosition { /// /// Mainly for internal use. static CameraPosition? fromMap(Object? json) { - if (json == null || !(json is Map)) { + if (json == null || json is! Map) { return null; } final LatLng? target = LatLng.fromJson(json['target']); @@ -80,22 +83,26 @@ class CameraPosition { return null; } return CameraPosition( - bearing: json['bearing'], + bearing: json['bearing'] as double, target: target, - tilt: json['tilt'], - zoom: json['zoom'], + tilt: json['tilt'] as double, + zoom: json['zoom'] as double, ); } @override bool operator ==(Object other) { - if (identical(this, other)) return true; - if (runtimeType != other.runtimeType) return false; - final CameraPosition typedOther = other as CameraPosition; - return bearing == typedOther.bearing && - target == typedOther.target && - tilt == typedOther.tilt && - zoom == typedOther.zoom; + if (identical(this, other)) { + return true; + } + if (runtimeType != other.runtimeType) { + return false; + } + return other is CameraPosition && + bearing == other.bearing && + target == other.target && + tilt == other.tilt && + zoom == other.zoom; } @override 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 1e9b2181778e..d9e4b2d705c9 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 @@ -3,8 +3,8 @@ // found in the LICENSE file. import 'package:flutter/foundation.dart' show VoidCallback; -import 'package:flutter/material.dart' show Color, Colors; import 'package:flutter/foundation.dart' show immutable; +import 'package:flutter/material.dart' show Color, Colors; import 'types.dart'; @@ -105,9 +105,11 @@ class Circle implements MapsObject { } /// Creates a new [Circle] object whose values are the same as this instance. + @override Circle clone() => copyWith(); /// Converts this object to something serializable in JSON. + @override Object toJson() { final Map json = {}; @@ -132,18 +134,22 @@ class Circle implements MapsObject { @override bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final Circle typedOther = other as Circle; - return circleId == typedOther.circleId && - consumeTapEvents == typedOther.consumeTapEvents && - fillColor == typedOther.fillColor && - center == typedOther.center && - radius == typedOther.radius && - strokeColor == typedOther.strokeColor && - strokeWidth == typedOther.strokeWidth && - visible == typedOther.visible && - zIndex == typedOther.zIndex; + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is Circle && + circleId == other.circleId && + consumeTapEvents == other.consumeTapEvents && + fillColor == other.fillColor && + center == other.center && + radius == other.radius && + strokeColor == other.strokeColor && + strokeWidth == other.strokeWidth && + visible == other.visible && + zIndex == other.zIndex; } @override 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 5bc4ca608f1a..81fe08bb1329 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 @@ -2,9 +2,11 @@ // 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 visibleForTesting; +import 'package:flutter/foundation.dart' + show immutable, objectRuntimeType, visibleForTesting; /// A pair of latitude and longitude coordinates, stored as degrees. +@immutable class LatLng { /// Creates a geographical location specified in degrees [latitude] and /// [longitude]. @@ -17,7 +19,7 @@ class LatLng { : assert(latitude != null), assert(longitude != null), latitude = - (latitude < -90.0 ? -90.0 : (90.0 < latitude ? 90.0 : latitude)), + latitude < -90.0 ? -90.0 : (90.0 < latitude ? 90.0 : latitude), // Avoids normalization if possible to prevent unnecessary loss of precision longitude = longitude >= -180 && longitude < 180 ? longitude @@ -40,16 +42,19 @@ class LatLng { return null; } assert(json is List && json.length == 2); - final list = json as List; - return LatLng(list[0], list[1]); + final List list = json as List; + return LatLng(list[0]! as double, list[1]! as double); } @override - String toString() => '$runtimeType($latitude, $longitude)'; + String toString() => + '${objectRuntimeType(this, 'LatLng')}($latitude, $longitude)'; @override - bool operator ==(Object o) { - return o is LatLng && o.latitude == latitude && o.longitude == longitude; + bool operator ==(Object other) { + return other is LatLng && + other.latitude == latitude && + other.longitude == longitude; } @override @@ -64,6 +69,7 @@ class LatLng { /// if `southwest.longitude` ≤ `northeast.longitude`, /// * lng ∈ [-180, `northeast.longitude`] ∪ [`southwest.longitude`, 180], /// if `northeast.longitude` < `southwest.longitude` +@immutable class LatLngBounds { /// Creates geographical bounding box with the specified corners. /// @@ -110,7 +116,7 @@ class LatLngBounds { return null; } assert(json is List && json.length == 2); - final list = json as List; + final List list = json as List; return LatLngBounds( southwest: LatLng.fromJson(list[0])!, northeast: LatLng.fromJson(list[1])!, @@ -119,14 +125,14 @@ class LatLngBounds { @override String toString() { - return '$runtimeType($southwest, $northeast)'; + return '${objectRuntimeType(this, 'LatLngBounds')}($southwest, $northeast)'; } @override - bool operator ==(Object o) { - return o is LatLngBounds && - o.southwest == southwest && - o.northeast == northeast; + bool operator ==(Object other) { + return other is LatLngBounds && + other.southwest == southwest && + other.northeast == northeast; } @override 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 be629e174143..953746daa745 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 @@ -20,10 +20,13 @@ class MapsObjectId { @override bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final MapsObjectId typedOther = other as MapsObjectId; - return value == typedOther.value; + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is MapsObjectId && value == other.value; } @override 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 3267cad8d8a2..0051afcefbab 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 @@ -2,13 +2,15 @@ // 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 'package:flutter/foundation.dart' + show immutable, objectRuntimeType, setEquals; import 'maps_object.dart'; import 'utils/maps_object.dart'; /// Update specification for a set of objects. -class MapsObjectUpdates { +@immutable +class MapsObjectUpdates> { /// Computes updates given previous and current object sets. /// /// [objectName] is the prefix to use when serializing the updates into a JSON @@ -43,7 +45,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 as MapsObjectId]; + final T? previous = previousObjects[current.mapsId]; return current != previous; } @@ -62,21 +64,21 @@ class MapsObjectUpdates { return _objectsToAdd; } - late Set _objectsToAdd; + late final Set _objectsToAdd; /// Set of objects to be removed in this update. Set> get objectIdsToRemove { return _objectIdsToRemove; } - late Set> _objectIdsToRemove; + late final Set> _objectIdsToRemove; /// Set of objects to be changed in this update. Set get objectsToChange { return _objectsToChange; } - late Set _objectsToChange; + late final Set _objectsToChange; /// Converts this object to JSON. Object toJson() { 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 8057d2962e9e..914e77a64c9f 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 @@ -14,6 +14,7 @@ Object _offsetToJson(Offset offset) { } /// Text labels for a [Marker] info window. +@immutable class InfoWindow { /// Creates an immutable representation of a label on for [Marker]. const InfoWindow({ @@ -81,12 +82,16 @@ class InfoWindow { @override bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final InfoWindow typedOther = other as InfoWindow; - return title == typedOther.title && - snippet == typedOther.snippet && - anchor == typedOther.anchor; + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is InfoWindow && + title == other.title && + snippet == other.snippet && + anchor == other.anchor; } @override @@ -113,7 +118,7 @@ class MarkerId extends MapsObjectId { /// the map's surface; that is, it will not necessarily change orientation /// due to map rotations, tilting, or zooming. @immutable -class Marker implements MapsObject { +class Marker implements MapsObject { /// Creates a set of marker configuration options. /// /// Default marker options. @@ -258,9 +263,11 @@ class Marker implements MapsObject { } /// Creates a new [Marker] object whose values are the same as this instance. + @override Marker clone() => copyWith(); /// Converts this object to something serializable in JSON. + @override Object toJson() { final Map json = {}; @@ -287,21 +294,25 @@ class Marker implements MapsObject { @override bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final Marker typedOther = other as Marker; - return markerId == typedOther.markerId && - alpha == typedOther.alpha && - anchor == typedOther.anchor && - consumeTapEvents == typedOther.consumeTapEvents && - draggable == typedOther.draggable && - flat == typedOther.flat && - icon == typedOther.icon && - infoWindow == typedOther.infoWindow && - position == typedOther.position && - rotation == typedOther.rotation && - visible == typedOther.visible && - zIndex == typedOther.zIndex; + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is Marker && + markerId == other.markerId && + alpha == other.alpha && + anchor == other.anchor && + consumeTapEvents == other.consumeTapEvents && + draggable == other.draggable && + flat == other.flat && + icon == other.icon && + infoWindow == other.infoWindow && + position == other.position && + rotation == other.rotation && + visible == other.visible && + zIndex == other.zIndex; } @override 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 7b6f24831e59..8653ba0ed0f6 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 @@ -20,7 +20,7 @@ class PolygonId extends MapsObjectId { /// Draws a polygon through geographical locations on the map. @immutable -class Polygon implements MapsObject { +class Polygon implements MapsObject { /// Creates an immutable representation of a polygon through geographical locations on the map. const Polygon({ required this.polygonId, @@ -123,11 +123,13 @@ class Polygon implements MapsObject { } /// Creates a new [Polygon] object whose values are the same as this instance. + @override Polygon clone() { return copyWith(pointsParam: List.of(points)); } /// Converts this object to something serializable in JSON. + @override Object toJson() { final Map json = {}; @@ -159,19 +161,23 @@ class Polygon implements MapsObject { @override bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final Polygon typedOther = other as Polygon; - return polygonId == typedOther.polygonId && - consumeTapEvents == typedOther.consumeTapEvents && - fillColor == typedOther.fillColor && - geodesic == typedOther.geodesic && - listEquals(points, typedOther.points) && - const DeepCollectionEquality().equals(holes, typedOther.holes) && - visible == typedOther.visible && - strokeColor == typedOther.strokeColor && - strokeWidth == typedOther.strokeWidth && - zIndex == typedOther.zIndex; + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is Polygon && + polygonId == other.polygonId && + consumeTapEvents == other.consumeTapEvents && + fillColor == other.fillColor && + geodesic == other.geodesic && + listEquals(points, other.points) && + const DeepCollectionEquality().equals(holes, other.holes) && + visible == other.visible && + strokeColor == other.strokeColor && + strokeWidth == other.strokeWidth && + zIndex == other.zIndex; } @override 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 00c718646229..39e62e3c0160 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 @@ -21,7 +21,7 @@ class PolylineId extends MapsObjectId { /// Draws a line through geographical locations on the map. @immutable -class Polyline implements MapsObject { +class Polyline implements MapsObject { /// Creates an immutable object representing a line drawn through geographical locations on the map. const Polyline({ required this.polylineId, @@ -150,6 +150,7 @@ class Polyline implements MapsObject { /// Creates a new [Polyline] object whose values are the same as this /// instance. + @override Polyline clone() { return copyWith( patternsParam: List.of(patterns), @@ -158,6 +159,7 @@ class Polyline implements MapsObject { } /// Converts this object to something serializable in JSON. + @override Object toJson() { final Map json = {}; @@ -191,21 +193,25 @@ class Polyline implements MapsObject { @override bool operator ==(Object other) { - if (identical(this, other)) return true; - if (other.runtimeType != runtimeType) return false; - final Polyline typedOther = other as Polyline; - return polylineId == typedOther.polylineId && - consumeTapEvents == typedOther.consumeTapEvents && - color == typedOther.color && - geodesic == typedOther.geodesic && - jointType == typedOther.jointType && - listEquals(patterns, typedOther.patterns) && - listEquals(points, typedOther.points) && - startCap == typedOther.startCap && - endCap == typedOther.endCap && - visible == typedOther.visible && - width == typedOther.width && - zIndex == typedOther.zIndex; + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is Polyline && + polylineId == other.polylineId && + consumeTapEvents == other.consumeTapEvents && + color == other.color && + geodesic == other.geodesic && + jointType == other.jointType && + listEquals(patterns, other.patterns) && + listEquals(points, other.points) && + startCap == other.startCap && + endCap == other.endCap && + visible == other.visible && + width == other.width && + zIndex == other.zIndex; } @override 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 b424aa5c00e4..b1d37dc2c234 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 @@ -2,7 +2,7 @@ // 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 immutable; +import 'package:flutter/foundation.dart' show immutable, objectRuntimeType; /// Represents a point coordinate in the [GoogleMap]'s view. /// @@ -26,17 +26,17 @@ class ScreenCoordinate { /// Converts this object to something serializable in JSON. Object toJson() { return { - "x": x, - "y": y, + 'x': x, + 'y': y, }; } @override - String toString() => '$runtimeType($x, $y)'; + String toString() => '${objectRuntimeType(this, 'ScreenCoordinate')}($x, $y)'; @override - bool operator ==(Object o) { - return o is ScreenCoordinate && o.x == x && o.y == y; + bool operator ==(Object other) { + return other is ScreenCoordinate && other.x == x && other.y == y; } @override 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 80b05272e21d..aaf0f800f47f 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 @@ -41,8 +41,8 @@ class TileOverlayId extends MapsObjectId { /// The coordinates of the tiles are measured from the top left (northwest) corner of the map. /// 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 implements MapsObject { +@immutable +class TileOverlay implements MapsObject { /// Creates an immutable representation of a [TileOverlay] to draw on [GoogleMap]. const TileOverlay({ required this.tileOverlayId, @@ -106,9 +106,11 @@ class TileOverlay implements MapsObject { ); } + @override TileOverlay clone() => copyWith(); /// Converts this object to JSON. + @override Object toJson() { final Map json = {}; 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 5e2e4c234ccf..1e1bef8ee6c0 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 @@ -7,25 +7,24 @@ export 'bitmap.dart'; export 'callbacks.dart'; export 'camera.dart'; export 'cap.dart'; -export 'circle_updates.dart'; export 'circle.dart'; +export 'circle_updates.dart'; export 'joint_type.dart'; export 'location.dart'; -export 'maps_object_updates.dart'; export 'maps_object.dart'; -export 'marker_updates.dart'; +export 'maps_object_updates.dart'; export 'marker.dart'; +export 'marker_updates.dart'; export 'pattern_item.dart'; -export 'polygon_updates.dart'; export 'polygon.dart'; -export 'polyline_updates.dart'; +export 'polygon_updates.dart'; export 'polyline.dart'; +export 'polyline_updates.dart'; export 'screen_coordinate.dart'; export 'tile.dart'; export 'tile_overlay.dart'; export 'tile_provider.dart'; export 'ui.dart'; - // Export the utils, they're used by the Widget export 'utils/circle.dart'; export 'utils/marker.dart'; 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 18f88b910b48..482f64be8b4f 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 @@ -2,6 +2,8 @@ // 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'; + import 'types.dart'; /// Type of map tiles to display. @@ -29,6 +31,7 @@ enum MapType { // Used with [GoogleMapOptions] to wrap a [LatLngBounds] value. This allows // distinguishing between specifying an unbounded target (null `LatLngBounds`) // from not specifying anything (null `CameraTargetBounds`). +@immutable class CameraTargetBounds { /// Creates a camera target bounds with the specified bounding box, or null /// to indicate that the camera target is not bounded. @@ -47,10 +50,13 @@ class CameraTargetBounds { @override bool operator ==(Object other) { - if (identical(this, other)) return true; - if (runtimeType != other.runtimeType) return false; - final CameraTargetBounds typedOther = other as CameraTargetBounds; - return bounds == typedOther.bounds; + if (identical(this, other)) { + return true; + } + if (runtimeType != other.runtimeType) { + return false; + } + return other is CameraTargetBounds && bounds == other.bounds; } @override @@ -66,6 +72,7 @@ class CameraTargetBounds { // Used with [GoogleMapOptions] to wrap min and max zoom. This allows // distinguishing between specifying unbounded zooming (null `minZoom` and // `maxZoom`) from not specifying anything (null `MinMaxZoomPreference`). +@immutable class MinMaxZoomPreference { /// Creates a immutable representation of the preferred minimum and maximum zoom values for the map camera. /// @@ -88,10 +95,15 @@ class MinMaxZoomPreference { @override bool operator ==(Object other) { - if (identical(this, other)) return true; - if (runtimeType != other.runtimeType) return false; - final MinMaxZoomPreference typedOther = other as MinMaxZoomPreference; - return minZoom == typedOther.minZoom && maxZoom == typedOther.maxZoom; + if (identical(this, other)) { + return true; + } + if (runtimeType != other.runtimeType) { + return false; + } + return other is MinMaxZoomPreference && + minZoom == other.minZoom && + maxZoom == other.maxZoom; } @override 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 da5a49825c7f..d17dbd279dfe 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,13 @@ import '../maps_object.dart'; /// Converts an [Iterable] of [MapsObject]s in a Map of [MapObjectId] -> [MapObject]. -Map, T> keyByMapsObjectId( +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, object.clone()))); } /// Converts a Set of [MapsObject]s into something serializable in JSON. -Object 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/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml index 998f31936c3b..759daf2bb1cb 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 @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/google_maps_fl issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 # 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: 2.1.6 +version: 2.1.7 environment: sdk: '>=2.12.0 <3.0.0' diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/method_channel/method_channel_google_maps_flutter_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/method_channel/method_channel_google_maps_flutter_test.dart index 9ae42ced6c42..e5052184915f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/method_channel/method_channel_google_maps_flutter_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/method_channel/method_channel_google_maps_flutter_test.dart @@ -2,13 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:async/async.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; - import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; -import 'package:async/async.dart'; - void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -39,8 +37,8 @@ void main() { final ByteData byteData = const StandardMethodCodec() .encodeMethodCall(MethodCall(method, data)); await TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger - .handlePlatformMessage( - "plugins.flutter.io/google_maps_$mapId", byteData, (data) {}); + .handlePlatformMessage('plugins.flutter.io/google_maps_$mapId', + byteData, (ByteData? data) {}); } // Calls each method that uses invokeMethod with a return type other than @@ -66,8 +64,8 @@ void main() { } }); - await maps.getLatLng(ScreenCoordinate(x: 0, y: 0), mapId: mapId); - await maps.isMarkerInfoWindowShown(MarkerId(''), mapId: mapId); + await maps.getLatLng(const ScreenCoordinate(x: 0, y: 0), mapId: mapId); + await maps.isMarkerInfoWindowShown(const MarkerId(''), mapId: mapId); await maps.getZoomLevel(mapId: mapId); await maps.takeSnapshot(mapId: mapId); // Check that all the invokeMethod calls happened. @@ -80,20 +78,20 @@ void main() { }); test('markers send drag event to correct streams', () async { const int mapId = 1; - final jsonMarkerDragStartEvent = { - "mapId": mapId, - "markerId": "drag-start-marker", - "position": [1.0, 1.0] + final Map jsonMarkerDragStartEvent = { + 'mapId': mapId, + 'markerId': 'drag-start-marker', + 'position': [1.0, 1.0] }; - final jsonMarkerDragEvent = { - "mapId": mapId, - "markerId": "drag-marker", - "position": [1.0, 1.0] + final Map jsonMarkerDragEvent = { + 'mapId': mapId, + 'markerId': 'drag-marker', + 'position': [1.0, 1.0] }; - final jsonMarkerDragEndEvent = { - "mapId": mapId, - "markerId": "drag-end-marker", - "position": [1.0, 1.0] + final Map jsonMarkerDragEndEvent = { + 'mapId': mapId, + 'markerId': 'drag-end-marker', + 'position': [1.0, 1.0] }; final MethodChannelGoogleMapsFlutter maps = @@ -101,23 +99,24 @@ void main() { maps.ensureChannelInitialized(mapId); final StreamQueue markerDragStartStream = - StreamQueue(maps.onMarkerDragStart(mapId: mapId)); + StreamQueue( + maps.onMarkerDragStart(mapId: mapId)); final StreamQueue markerDragStream = - StreamQueue(maps.onMarkerDrag(mapId: mapId)); + StreamQueue(maps.onMarkerDrag(mapId: mapId)); final StreamQueue markerDragEndStream = - StreamQueue(maps.onMarkerDragEnd(mapId: mapId)); + StreamQueue(maps.onMarkerDragEnd(mapId: mapId)); await sendPlatformMessage( - mapId, "marker#onDragStart", jsonMarkerDragStartEvent); - await sendPlatformMessage(mapId, "marker#onDrag", jsonMarkerDragEvent); + mapId, 'marker#onDragStart', jsonMarkerDragStartEvent); + await sendPlatformMessage(mapId, 'marker#onDrag', jsonMarkerDragEvent); await sendPlatformMessage( - mapId, "marker#onDragEnd", jsonMarkerDragEndEvent); + mapId, 'marker#onDragEnd', jsonMarkerDragEndEvent); expect((await markerDragStartStream.next).value.value, - equals("drag-start-marker")); - expect((await markerDragStream.next).value.value, equals("drag-marker")); + equals('drag-start-marker')); + expect((await markerDragStream.next).value.value, equals('drag-marker')); expect((await markerDragEndStream.next).value.value, - equals("drag-end-marker")); + equals('drag-end-marker')); }); }); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart index bdbaff7e2599..0899bb6a8fb2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart @@ -6,11 +6,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/services.dart'; -import 'package:mockito/mockito.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:mockito/mockito.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -50,7 +49,8 @@ void main() { platform.buildViewWithTextDirection( 0, (_) {}, - initialCameraPosition: CameraPosition(target: LatLng(0.0, 0.0)), + initialCameraPosition: + const CameraPosition(target: LatLng(0.0, 0.0)), textDirection: TextDirection.ltr, ), isA(), diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/bitmap_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/bitmap_test.dart index 6d02b2c630df..7fbaf4998355 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/bitmap_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/bitmap_test.dart @@ -13,13 +13,14 @@ void main() { group('$BitmapDescriptor', () { test('toJson / fromJson', () { - final descriptor = + final BitmapDescriptor descriptor = BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueCyan); - final json = descriptor.toJson(); + final Object json = descriptor.toJson(); // Rehydrate a new bitmap descriptor... // ignore: deprecated_member_use_from_same_package - final descriptorFromJson = BitmapDescriptor.fromJson(json); + final BitmapDescriptor descriptorFromJson = + BitmapDescriptor.fromJson(json); expect(descriptorFromJson, isNot(descriptor)); // New instance expect(identical(descriptorFromJson.toJson(), json), isTrue); // Same JSON @@ -28,81 +29,85 @@ void main() { group('fromJson validation', () { group('type validation', () { test('correct type', () { - expect(BitmapDescriptor.fromJson(['defaultMarker']), + expect(BitmapDescriptor.fromJson(['defaultMarker']), isA()); }); test('wrong type', () { expect(() { - BitmapDescriptor.fromJson(['bogusType']); + BitmapDescriptor.fromJson(['bogusType']); }, throwsAssertionError); }); }); group('defaultMarker', () { test('hue is null', () { - expect(BitmapDescriptor.fromJson(['defaultMarker']), + expect(BitmapDescriptor.fromJson(['defaultMarker']), isA()); }); test('hue is number', () { - expect(BitmapDescriptor.fromJson(['defaultMarker', 158]), + expect(BitmapDescriptor.fromJson(['defaultMarker', 158]), isA()); }); test('hue is not number', () { expect(() { - BitmapDescriptor.fromJson(['defaultMarker', 'nope']); + BitmapDescriptor.fromJson(['defaultMarker', 'nope']); }, throwsAssertionError); }); test('hue is out of range', () { expect(() { - BitmapDescriptor.fromJson(['defaultMarker', -1]); + BitmapDescriptor.fromJson(['defaultMarker', -1]); }, throwsAssertionError); expect(() { - BitmapDescriptor.fromJson(['defaultMarker', 361]); + BitmapDescriptor.fromJson(['defaultMarker', 361]); }, throwsAssertionError); }); }); group('fromBytes', () { test('with bytes', () { expect( - BitmapDescriptor.fromJson([ + BitmapDescriptor.fromJson([ 'fromBytes', - Uint8List.fromList([1, 2, 3]) + Uint8List.fromList([1, 2, 3]) ]), isA()); }); test('without bytes', () { expect(() { - BitmapDescriptor.fromJson(['fromBytes', null]); + BitmapDescriptor.fromJson(['fromBytes', null]); }, throwsAssertionError); expect(() { - BitmapDescriptor.fromJson(['fromBytes', []]); + BitmapDescriptor.fromJson(['fromBytes', []]); }, throwsAssertionError); }); }); group('fromAsset', () { test('name is passed', () { - expect(BitmapDescriptor.fromJson(['fromAsset', 'some/path.png']), + expect( + BitmapDescriptor.fromJson( + ['fromAsset', 'some/path.png']), isA()); }); test('name cannot be null or empty', () { expect(() { - BitmapDescriptor.fromJson(['fromAsset', null]); + BitmapDescriptor.fromJson(['fromAsset', null]); }, throwsAssertionError); expect(() { - BitmapDescriptor.fromJson(['fromAsset', '']); + BitmapDescriptor.fromJson(['fromAsset', '']); }, throwsAssertionError); }); test('package is passed', () { expect( BitmapDescriptor.fromJson( - ['fromAsset', 'some/path.png', 'some_package']), + ['fromAsset', 'some/path.png', 'some_package']), isA()); }); test('package cannot be null or empty', () { expect(() { - BitmapDescriptor.fromJson(['fromAsset', 'some/path.png', null]); + BitmapDescriptor.fromJson( + ['fromAsset', 'some/path.png', null]); }, throwsAssertionError); expect(() { - BitmapDescriptor.fromJson(['fromAsset', 'some/path.png', '']); + BitmapDescriptor.fromJson( + ['fromAsset', 'some/path.png', '']); }, throwsAssertionError); }); }); @@ -110,34 +115,34 @@ void main() { test('name and dpi passed', () { expect( BitmapDescriptor.fromJson( - ['fromAssetImage', 'some/path.png', 1.0]), + ['fromAssetImage', 'some/path.png', 1.0]), isA()); }); test('name cannot be null or empty', () { expect(() { - BitmapDescriptor.fromJson(['fromAssetImage', null, 1.0]); + BitmapDescriptor.fromJson(['fromAssetImage', null, 1.0]); }, throwsAssertionError); expect(() { - BitmapDescriptor.fromJson(['fromAssetImage', '', 1.0]); + BitmapDescriptor.fromJson(['fromAssetImage', '', 1.0]); }, throwsAssertionError); }); test('dpi must be number', () { expect(() { BitmapDescriptor.fromJson( - ['fromAssetImage', 'some/path.png', null]); + ['fromAssetImage', 'some/path.png', null]); }, throwsAssertionError); expect(() { BitmapDescriptor.fromJson( - ['fromAssetImage', 'some/path.png', 'one']); + ['fromAssetImage', 'some/path.png', 'one']); }, throwsAssertionError); }); test('with optional [width, height] List', () { expect( - BitmapDescriptor.fromJson([ + BitmapDescriptor.fromJson([ 'fromAssetImage', 'some/path.png', 1.0, - [640, 480] + [640, 480] ]), isA()); }); @@ -146,18 +151,18 @@ void main() { () { expect(() { BitmapDescriptor.fromJson( - ['fromAssetImage', 'some/path.png', 1.0, null]); + ['fromAssetImage', 'some/path.png', 1.0, null]); }, throwsAssertionError); expect(() { BitmapDescriptor.fromJson( - ['fromAssetImage', 'some/path.png', 1.0, []]); + ['fromAssetImage', 'some/path.png', 1.0, []]); }, throwsAssertionError); expect(() { - BitmapDescriptor.fromJson([ + BitmapDescriptor.fromJson([ 'fromAssetImage', 'some/path.png', 1.0, - [640, 480, 1024] + [640, 480, 1024] ]); }, throwsAssertionError); }); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/camera_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/camera_test.dart index 11665d904556..70e57aa67ac9 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/camera_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/camera_test.dart @@ -9,13 +9,14 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); test('toMap / fromMap', () { - const cameraPosition = CameraPosition( + const CameraPosition cameraPosition = CameraPosition( target: LatLng(10.0, 15.0), bearing: 0.5, tilt: 30.0, zoom: 1.5); // Cast to to ensure that recreating from JSON, where // type information will have likely been lost, still works. - final json = (cameraPosition.toMap() as Map) - .cast(); - final cameraPositionFromJson = CameraPosition.fromMap(json); + final Map json = + (cameraPosition.toMap() as Map) + .cast(); + final CameraPosition? cameraPositionFromJson = CameraPosition.fromMap(json); expect(cameraPosition, cameraPositionFromJson); }); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/location_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/location_test.dart index 80f696177dfd..9da3e543ea58 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/location_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/location_test.dart @@ -10,50 +10,50 @@ void main() { group('LanLng constructor', () { test('Maintains longitude precision if within acceptable range', () async { - const lat = -34.509981; - const lng = 150.792384; + const double lat = -34.509981; + const double lng = 150.792384; - final latLng = LatLng(lat, lng); + const LatLng latLng = LatLng(lat, lng); expect(latLng.latitude, equals(lat)); expect(latLng.longitude, equals(lng)); }); test('Normalizes longitude that is below lower limit', () async { - const lat = -34.509981; - const lng = -270.0; + const double lat = -34.509981; + const double lng = -270.0; - final latLng = LatLng(lat, lng); + const LatLng latLng = LatLng(lat, lng); expect(latLng.latitude, equals(lat)); expect(latLng.longitude, equals(90.0)); }); test('Normalizes longitude that is above upper limit', () async { - const lat = -34.509981; - const lng = 270.0; + const double lat = -34.509981; + const double lng = 270.0; - final latLng = LatLng(lat, lng); + const LatLng latLng = LatLng(lat, lng); expect(latLng.latitude, equals(lat)); expect(latLng.longitude, equals(-90.0)); }); test('Includes longitude set to lower limit', () async { - const lat = -34.509981; - const lng = -180.0; + const double lat = -34.509981; + const double lng = -180.0; - final latLng = LatLng(lat, lng); + const LatLng latLng = LatLng(lat, lng); expect(latLng.latitude, equals(lat)); expect(latLng.longitude, equals(-180.0)); }); test('Normalizes longitude set to upper limit', () async { - const lat = -34.509981; - const lng = 180.0; + const double lat = -34.509981; + const double lng = 180.0; - final latLng = LatLng(lat, lng); + const LatLng latLng = LatLng(lat, lng); expect(latLng.latitude, equals(lat)); expect(latLng.longitude, equals(-180.0)); 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 c2ca2bdda5b7..7c5106c23173 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 @@ -37,9 +37,9 @@ void main() { expect( serializeMapsObjectSet({object1, object2, object3}), >[ - {'id': '1'}, - {'id': '2'}, - {'id': '3'} + {'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 73ed1d9d1a90..414196b8333c 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 @@ -30,24 +30,25 @@ void main() { TestMapsObject(MapsObjectId('id3'), data: 2); const TestMapsObject to4 = TestMapsObject(MapsObjectId('id4')); - final Set previous = - Set.from([to1, to2, to3]); - final Set current = - Set.from([to2, to3Changed, to4]); + final Set previous = {to1, to2, to3}; + final Set current = { + to2, + to3Changed, + to4 + }; final TestMapsObjectUpdate updates = TestMapsObjectUpdate.from(previous, current); final Set> toRemove = - Set.from(>[ + >{ const MapsObjectId('id1') - ]); + }; expect(updates.objectIdsToRemove, toRemove); - final Set toAdd = Set.from([to4]); + final Set toAdd = {to4}; expect(updates.objectsToAdd, toAdd); - final Set toChange = - Set.from([to3Changed]); + final Set toChange = {to3Changed}; expect(updates.objectsToChange, toChange); }); @@ -62,10 +63,12 @@ void main() { TestMapsObject(MapsObjectId('id3'), data: 2); const TestMapsObject to4 = TestMapsObject(MapsObjectId('id4')); - final Set previous = - Set.from([to1, to2, to3]); - final Set current = - Set.from([to2, to3Changed, to4]); + final Set previous = {to1, to2, to3}; + final Set current = { + to2, + to3Changed, + to4 + }; final TestMapsObjectUpdate updates = TestMapsObjectUpdate.from(previous, current); @@ -90,13 +93,18 @@ void main() { TestMapsObject(MapsObjectId('id3'), data: 2); const 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 Set previous = {to1, to2, to3}; + final Set current1 = { + to2, + to3Changed, + to4 + }; + final Set current2 = { + to2, + to3Changed, + to4 + }; + final Set current3 = {to2, to4}; final TestMapsObjectUpdate updates1 = TestMapsObjectUpdate.from(previous, current1); final TestMapsObjectUpdate updates2 = @@ -118,10 +126,12 @@ void main() { TestMapsObject(MapsObjectId('id3'), data: 2); const TestMapsObject to4 = TestMapsObject(MapsObjectId('id4')); - final Set previous = - Set.from([to1, to2, to3]); - final Set current = - Set.from([to2, to3Changed, to4]); + final Set previous = {to1, to2, to3}; + final Set current = { + to2, + to3Changed, + to4 + }; final TestMapsObjectUpdate updates = TestMapsObjectUpdate.from(previous, current); expect( @@ -143,10 +153,12 @@ void main() { TestMapsObject(MapsObjectId('id3'), data: 2); const TestMapsObject to4 = TestMapsObject(MapsObjectId('id4')); - final Set previous = - Set.from([to1, to2, to3]); - final Set current = - Set.from([to2, to3Changed, to4]); + final Set previous = {to1, to2, to3}; + final Set current = { + to2, + to3Changed, + to4 + }; final TestMapsObjectUpdate updates = TestMapsObjectUpdate.from(previous, current); expect( diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/marker_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/marker_test.dart index c8f6fa527a95..db7afcbb0398 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/marker_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/marker_test.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/cupertino.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; @@ -12,7 +11,7 @@ void main() { group('$Marker', () { test('constructor defaults', () { - final Marker marker = Marker(markerId: MarkerId("ABC123")); + const Marker marker = Marker(markerId: MarkerId('ABC123')); expect(marker.alpha, equals(1.0)); expect(marker.anchor, equals(const Offset(0.5, 1.0))); @@ -31,9 +30,10 @@ void main() { expect(marker.onDragEnd, equals(null)); }); test('constructor alpha is >= 0.0 and <= 1.0', () { - final ValueSetter initWithAlpha = (double alpha) { - Marker(markerId: MarkerId("ABC123"), alpha: alpha); - }; + void initWithAlpha(double alpha) { + Marker(markerId: const MarkerId('ABC123'), alpha: alpha); + } + expect(() => initWithAlpha(-0.5), throwsAssertionError); expect(() => initWithAlpha(0.0), isNot(throwsAssertionError)); expect(() => initWithAlpha(0.5), isNot(throwsAssertionError)); @@ -45,19 +45,19 @@ void main() { final BitmapDescriptor testDescriptor = BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueCyan); final Marker marker = Marker( - markerId: MarkerId("ABC123"), + markerId: const MarkerId('ABC123'), alpha: 0.12345, - anchor: Offset(100, 100), + anchor: const Offset(100, 100), consumeTapEvents: true, draggable: true, flat: true, icon: testDescriptor, - infoWindow: InfoWindow( - title: "Test title", - snippet: "Test snippet", + infoWindow: const InfoWindow( + title: 'Test title', + snippet: 'Test snippet', anchor: Offset(100, 200), ), - position: LatLng(50, 50), + position: const LatLng(50, 50), rotation: 100, visible: false, zIndex: 100, @@ -70,7 +70,7 @@ void main() { final Map json = marker.toJson() as Map; expect(json, { - 'markerId': "ABC123", + 'markerId': 'ABC123', 'alpha': 0.12345, 'anchor': [100, 100], 'consumeTapEvents': true, @@ -78,8 +78,8 @@ void main() { 'flat': true, 'icon': testDescriptor.toJson(), 'infoWindow': { - 'title': "Test title", - 'snippet': "Test snippet", + 'title': 'Test title', + 'snippet': 'Test snippet', 'anchor': [100.0, 200.0], }, 'position': [50, 50], @@ -89,31 +89,31 @@ void main() { }); }); test('clone', () { - final Marker marker = Marker(markerId: MarkerId("ABC123")); + const Marker marker = Marker(markerId: MarkerId('ABC123')); final Marker clone = marker.clone(); expect(identical(clone, marker), isFalse); expect(clone, equals(marker)); }); test('copyWith', () { - final Marker marker = Marker(markerId: MarkerId("ABC123")); + const Marker marker = Marker(markerId: MarkerId('ABC123')); final BitmapDescriptor testDescriptor = BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueCyan); - final double testAlphaParam = 0.12345; - final Offset testAnchorParam = Offset(100, 100); + const double testAlphaParam = 0.12345; + const Offset testAnchorParam = Offset(100, 100); final bool testConsumeTapEventsParam = !marker.consumeTapEvents; final bool testDraggableParam = !marker.draggable; final bool testFlatParam = !marker.flat; final BitmapDescriptor testIconParam = testDescriptor; - final InfoWindow testInfoWindowParam = InfoWindow(title: "Test"); - final LatLng testPositionParam = LatLng(100, 100); - final double testRotationParam = 100; + const InfoWindow testInfoWindowParam = InfoWindow(title: 'Test'); + const LatLng testPositionParam = LatLng(100, 100); + const double testRotationParam = 100; final bool testVisibleParam = !marker.visible; - final double testZIndexParam = 100; - final List log = []; + const double testZIndexParam = 100; + final List log = []; - final copy = marker.copyWith( + final Marker copy = marker.copyWith( alphaParam: testAlphaParam, anchorParam: testAnchorParam, consumeTapEventsParam: testConsumeTapEventsParam, @@ -126,16 +126,16 @@ void main() { visibleParam: testVisibleParam, zIndexParam: testZIndexParam, onTapParam: () { - log.add("onTapParam"); + log.add('onTapParam'); }, onDragStartParam: (LatLng latLng) { - log.add("onDragStartParam"); + log.add('onDragStartParam'); }, onDragParam: (LatLng latLng) { - log.add("onDragParam"); + log.add('onDragParam'); }, onDragEndParam: (LatLng latLng) { - log.add("onDragEndParam"); + log.add('onDragEndParam'); }, ); @@ -152,16 +152,16 @@ void main() { expect(copy.zIndex, equals(testZIndexParam)); copy.onTap!(); - expect(log, contains("onTapParam")); + expect(log, contains('onTapParam')); - copy.onDragStart!(LatLng(0, 1)); - expect(log, contains("onDragStartParam")); + copy.onDragStart!(const LatLng(0, 1)); + expect(log, contains('onDragStartParam')); - copy.onDrag!(LatLng(0, 1)); - expect(log, contains("onDragParam")); + copy.onDrag!(const LatLng(0, 1)); + expect(log, contains('onDragParam')); - copy.onDragEnd!(LatLng(0, 1)); - expect(log, contains("onDragEndParam")); + copy.onDragEnd!(const LatLng(0, 1)); + expect(log, contains('onDragEndParam')); }); }); } 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 e28da7ab79ad..0da077dbc300 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 @@ -2,13 +2,16 @@ // 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'; import 'package:google_maps_flutter_platform_interface/src/types/maps_object.dart'; import 'package:google_maps_flutter_platform_interface/src/types/maps_object_updates.dart'; /// A trivial TestMapsObject implementation for testing updates with. -class TestMapsObject implements MapsObject { +@immutable +class TestMapsObject implements MapsObject { const TestMapsObject(this.mapsId, {this.data = 1}); + @override final MapsObjectId mapsId; final int data; 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 c3ccf695032b..1a9a9d480f1a 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 @@ -8,7 +8,7 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf class _TestTileProvider extends TileProvider { @override Future getTile(int x, int y, int? zoom) async { - return Tile(0, 0, null); + return const Tile(0, 0, null); } } @@ -65,7 +65,7 @@ void main() { test('equality', () async { final TileProvider tileProvider = _TestTileProvider(); final TileOverlay tileOverlay1 = TileOverlay( - tileOverlayId: TileOverlayId('id1'), + tileOverlayId: const TileOverlayId('id1'), fadeIn: false, tileProvider: tileProvider, transparency: 0.1, @@ -73,7 +73,7 @@ void main() { visible: false, tileSize: 128); final TileOverlay tileOverlaySameValues = TileOverlay( - tileOverlayId: TileOverlayId('id1'), + tileOverlayId: const TileOverlayId('id1'), fadeIn: false, tileProvider: tileProvider, transparency: 0.1, @@ -81,14 +81,14 @@ void main() { visible: false, tileSize: 128); final TileOverlay tileOverlayDifferentId = TileOverlay( - tileOverlayId: TileOverlayId('id2'), + tileOverlayId: const TileOverlayId('id2'), fadeIn: false, tileProvider: tileProvider, transparency: 0.1, zIndex: 1, visible: false, tileSize: 128); - final TileOverlay tileOverlayDifferentProvider = TileOverlay( + const TileOverlay tileOverlayDifferentProvider = TileOverlay( tileOverlayId: TileOverlayId('id1'), fadeIn: false, tileProvider: null, @@ -105,7 +105,7 @@ void main() { final TileProvider tileProvider = _TestTileProvider(); // Set non-default values for every parameter. final TileOverlay tileOverlay = TileOverlay( - tileOverlayId: TileOverlayId('id1'), + tileOverlayId: const TileOverlayId('id1'), fadeIn: false, tileProvider: tileProvider, transparency: 0.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 fbb345c50563..b62f7326d831 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 @@ -18,20 +18,20 @@ void main() { const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); - final Set previous = Set.from([to1, to2, to3]); - final Set current = - Set.from([to2, to3Changed, to4]); + final Set previous = {to1, to2, to3}; + final Set current = {to2, to3Changed, to4}; final TileOverlayUpdates updates = TileOverlayUpdates.from(previous, current); - final Set toRemove = - Set.from([const TileOverlayId('id1')]); + final Set toRemove = { + const TileOverlayId('id1') + }; expect(updates.tileOverlayIdsToRemove, toRemove); - final Set toAdd = Set.from([to4]); + final Set toAdd = {to4}; expect(updates.tileOverlaysToAdd, toAdd); - final Set toChange = Set.from([to3Changed]); + final Set toChange = {to3Changed}; expect(updates.tileOverlaysToChange, toChange); }); @@ -42,9 +42,8 @@ void main() { const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); - final Set previous = Set.from([to1, to2, to3]); - final Set current = - Set.from([to2, to3Changed, to4]); + final Set previous = {to1, to2, to3}; + final Set current = {to2, to3Changed, to4}; final TileOverlayUpdates updates = TileOverlayUpdates.from(previous, current); @@ -66,12 +65,10 @@ void main() { const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('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 Set previous = {to1, to2, to3}; + final Set current1 = {to2, to3Changed, to4}; + final Set current2 = {to2, to3Changed, to4}; + final Set current3 = {to2, to4}; final TileOverlayUpdates updates1 = TileOverlayUpdates.from(previous, current1); final TileOverlayUpdates updates2 = @@ -89,9 +86,8 @@ void main() { const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); - final Set previous = Set.from([to1, to2, to3]); - final Set current = - Set.from([to2, to3Changed, to4]); + final Set previous = {to1, to2, to3}; + final Set current = {to2, to3Changed, to4}; final TileOverlayUpdates updates = TileOverlayUpdates.from(previous, current); expect( @@ -109,9 +105,8 @@ void main() { const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); - final Set previous = Set.from([to1, to2, to3]); - final Set current = - Set.from([to2, to3Changed, to4]); + final Set previous = {to1, to2, to3}; + final Set current = {to2, to3Changed, to4}; final TileOverlayUpdates updates = TileOverlayUpdates.from(previous, current); expect( 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 653958474185..ab49fd1a6c56 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 @@ -12,7 +12,7 @@ void main() { group('tile tests', () { test('toJson returns correct format', () async { - final Uint8List data = Uint8List.fromList([0, 1]); + final Uint8List data = Uint8List.fromList([0, 1]); final Tile tile = Tile(100, 200, data); final Object json = tile.toJson(); expect(json, { diff --git a/script/configs/custom_analysis.yaml b/script/configs/custom_analysis.yaml index bcd7d37dea0a..f735019d61c4 100644 --- a/script/configs/custom_analysis.yaml +++ b/script/configs/custom_analysis.yaml @@ -1,14 +1,12 @@ # Plugins that deliberately use their own analysis_options.yaml. # -# This only exists to allow incrementally switching to the newer, stricter -# analysis_options.yaml based on flutter/flutter, rather than the original -# rules based on pedantic (now at analysis_options_legacy.yaml). +# This only exists to allow incrementally adopting new analysis options in +# cases where a new option can't be applied to the entire repository at +# once. Do not add anything to this file without an issue reference and +# a concrete plan for removing it relatively quickly. # # DO NOT move or delete this file without updating # https://github.com/dart-lang/sdk/blob/master/tools/bots/flutter/analyze_flutter_plugins.sh # which references this file from source, but out-of-repo. # Contact stuartmorgan or devoncarew for assistance if necessary. -# TODO(ecosystem): Remove everything from this list. See: -# https://github.com/flutter/flutter/issues/76229 -- google_maps_flutter/google_maps_flutter_platform_interface diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md index 4b40aecefa9a..adc7bfcd29ae 100644 --- a/script/tool/CHANGELOG.md +++ b/script/tool/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +- Supports empty custom analysis allow list files. + ## 0.8.6 - Adds `update-release-info` to apply changelog and optional version changes diff --git a/script/tool/lib/src/analyze_command.dart b/script/tool/lib/src/analyze_command.dart index 1cd85af076fc..8778b3de9d86 100644 --- a/script/tool/lib/src/analyze_command.dart +++ b/script/tool/lib/src/analyze_command.dart @@ -87,9 +87,11 @@ class AnalyzeCommand extends PackageLoopingCommand { getStringListArg(_customAnalysisFlag).expand((String item) { if (item.endsWith('.yaml')) { final File file = packagesDir.fileSystem.file(item); - return (loadYaml(file.readAsStringSync()) as YamlList) - .toList() - .cast(); + final Object? yaml = loadYaml(file.readAsStringSync()); + if (yaml == null) { + return []; + } + return (yaml as YamlList).toList().cast(); } return [item]; }).toSet(); diff --git a/script/tool/test/analyze_command_test.dart b/script/tool/test/analyze_command_test.dart index a9b83349306f..a4a47a221189 100644 --- a/script/tool/test/analyze_command_test.dart +++ b/script/tool/test/analyze_command_test.dart @@ -213,6 +213,18 @@ void main() { ])); }); + test('allows an empty config file', () async { + createFakePlugin('foo', packagesDir, + extraFiles: ['analysis_options.yaml']); + final File allowFile = packagesDir.childFile('custom.yaml'); + allowFile.createSync(); + + await expectLater( + () => runCapturingPrint( + runner, ['analyze', '--custom-analysis', allowFile.path]), + throwsA(isA())); + }); + // See: https://github.com/flutter/flutter/issues/78994 test('takes an empty allow list', () async { createFakePlugin('foo', packagesDir,