From d7125cdb91c0ea6781bfc9ca8c570070592aa851 Mon Sep 17 00:00:00 2001 From: Guy Kogus Date: Wed, 17 Mar 2021 21:23:52 +0100 Subject: [PATCH 1/3] [google_maps_flutter_platform_interface] Mark constructors as const for ids (#3718) --- .../CHANGELOG.md | 4 ++ .../method_channel_google_maps_flutter.dart | 6 +- .../lib/src/types/camera.dart | 6 +- .../lib/src/types/circle.dart | 2 +- .../lib/src/types/maps_object.dart | 2 +- .../lib/src/types/marker.dart | 2 +- .../lib/src/types/polygon.dart | 4 +- .../lib/src/types/polyline.dart | 2 +- .../lib/src/types/tile_overlay.dart | 5 +- .../pubspec.yaml | 2 +- .../test/types/camera_test.dart | 3 +- .../test/types/maps_object_test.dart | 24 ++++---- .../test/types/maps_object_updates_test.dart | 60 ++++++++++--------- .../test/types/test_maps_object.dart | 5 +- .../test/types/tile_overlay_test.dart | 25 ++++---- .../test/types/tile_overlay_updates_test.dart | 57 +++++++++--------- .../test/types/tile_test.dart | 3 +- 17 files changed, 111 insertions(+), 101 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 b0ad668c8ddc..e8b12f79220d 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.2 + +* Mark constructors for CameraUpdate, CircleId, MapsObjectId, MarkerId, PolygonId, PolylineId and TileOverlayId as const + ## 2.0.1 * Update platform_plugin_interface version requirement. 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 3d16127ab7a9..9d447701fdd8 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 @@ -5,13 +5,13 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; import 'package:flutter/gestures.dart'; - +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:stream_transform/stream_transform.dart'; + import '../types/tile_overlay_updates.dart'; import '../types/utils/tile_overlay.dart'; 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 28acf35962b6..f15254104b0e 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 @@ -109,7 +109,7 @@ class CameraPosition { /// Defines a camera move, supporting absolute moves as well as moves relative /// the current position. class CameraUpdate { - CameraUpdate._(this._json); + const CameraUpdate._(this._json); /// Returns a camera update that moves the camera to the specified position. static CameraUpdate newCameraPosition(CameraPosition cameraPosition) { @@ -176,7 +176,7 @@ class CameraUpdate { /// /// Equivalent to the result of calling `zoomBy(1.0)`. static CameraUpdate zoomIn() { - return CameraUpdate._(['zoomIn']); + return const CameraUpdate._(['zoomIn']); } /// Returns a camera update that zooms the camera out, bringing the camera @@ -184,7 +184,7 @@ class CameraUpdate { /// /// Equivalent to the result of calling `zoomBy(-1.0)`. static CameraUpdate zoomOut() { - return CameraUpdate._(['zoomOut']); + return const CameraUpdate._(['zoomOut']); } /// Returns a camera update that sets the camera zoom level. 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 e3198dfd6512..daf7c918f67a 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 @@ -14,7 +14,7 @@ import 'types.dart'; @immutable class CircleId extends MapsObjectId { /// Creates an immutable identifier for a [Circle]. - CircleId(String value) : super(value); + const CircleId(String value) : super(value); } /// Draws a circle on the map. 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 545d46272215..1e7932c7cde2 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 @@ -14,7 +14,7 @@ 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); + const MapsObjectId(this.value) : assert(value != null); /// The value of the id. final String 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 15351d58168b..e493d6cec8cc 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 @@ -104,7 +104,7 @@ class InfoWindow { @immutable class MarkerId extends MapsObjectId { /// Creates an immutable identifier for a [Marker]. - MarkerId(String value) : super(value); + const MarkerId(String value) : super(value); } /// Marks a geographical location on the map. 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 4e5e9bf13d84..57438287a156 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 @@ -15,7 +15,7 @@ import 'types.dart'; @immutable class PolygonId extends MapsObjectId { /// Creates an immutable identifier for a [Polygon]. - PolygonId(String value) : super(value); + const PolygonId(String value) : super(value); } /// Draws a polygon through geographical locations on the map. @@ -167,7 +167,7 @@ class Polygon implements MapsObject { fillColor == typedOther.fillColor && geodesic == typedOther.geodesic && listEquals(points, typedOther.points) && - DeepCollectionEquality().equals(holes, typedOther.holes) && + const DeepCollectionEquality().equals(holes, typedOther.holes) && visible == typedOther.visible && strokeColor == typedOther.strokeColor && strokeWidth == typedOther.strokeWidth && 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 3f87395164f6..6738bbf2f079 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 @@ -16,7 +16,7 @@ class PolylineId extends MapsObjectId { /// Creates an immutable object representing a [PolylineId] among [GoogleMap] polylines. /// /// An [AssertionError] will be thrown if [value] is null. - PolylineId(String value) : super(value); + const PolylineId(String value) : super(value); } /// Draws a line through geographical locations on the map. 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 e31bfb461fb4..7f7ef09123b0 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 @@ -3,16 +3,17 @@ // found in the LICENSE file. import 'dart:ui' show hashValues; + import 'package:flutter/foundation.dart'; +import 'package:meta/meta.dart' show immutable; import 'types.dart'; -import 'package:meta/meta.dart' show immutable; /// Uniquely identifies a [TileOverlay] among [GoogleMap] tile overlays. @immutable class TileOverlayId extends MapsObjectId { /// Creates an immutable identifier for a [TileOverlay]. - TileOverlayId(String value) : super(value); + const TileOverlayId(String value) : super(value); } /// A set of images which are displayed on top of the base map tiles. 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 0796b71fbb62..9d419351e85f 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: 2.0.1 +version: 2.0.2 dependencies: flutter: 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 3b6d237e05d4..4774311feb90 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 @@ -3,14 +3,13 @@ // 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'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); test('toMap / fromMap', () { - final cameraPosition = CameraPosition( + const 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. 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 65692bd2a385..2d1ae8314a94 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,12 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); 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); + const MapsObjectId id1 = MapsObjectId('1'); + const MapsObjectId id2 = MapsObjectId('2'); + const MapsObjectId id3 = MapsObjectId('3'); + const TestMapsObject object1 = TestMapsObject(id1); + const TestMapsObject object2 = TestMapsObject(id2, data: 2); + const TestMapsObject object3 = TestMapsObject(id3); expect( keyByMapsObjectId({object1, object2, object3}), , TestMapsObject>{ @@ -28,12 +28,12 @@ void main() { }); 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); + const MapsObjectId id1 = MapsObjectId('1'); + const MapsObjectId id2 = MapsObjectId('2'); + const MapsObjectId id3 = MapsObjectId('3'); + const TestMapsObject object1 = TestMapsObject(id1); + const TestMapsObject object2 = TestMapsObject(id2, data: 2); + const TestMapsObject object3 = TestMapsObject(id3); expect( serializeMapsObjectSet({object1, object2, object3}), >[ 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 68f4c587c2f2..673b3c63c59e 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 @@ -6,9 +6,9 @@ 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 'package:google_maps_flutter_platform_interface/src/types/maps_object_updates.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/utils/maps_object.dart'; import 'test_maps_object.dart'; @@ -23,15 +23,15 @@ void main() { group('tile overlay updates tests', () { test('Correctly set toRemove, toAdd and toChange', () async { - final TestMapsObject to1 = + const TestMapsObject to1 = TestMapsObject(MapsObjectId('id1')); - final TestMapsObject to2 = + const TestMapsObject to2 = TestMapsObject(MapsObjectId('id2')); - final TestMapsObject to3 = + const TestMapsObject to3 = TestMapsObject(MapsObjectId('id3')); - final TestMapsObject to3Changed = + const TestMapsObject to3Changed = TestMapsObject(MapsObjectId('id3'), data: 2); - final TestMapsObject to4 = + const TestMapsObject to4 = TestMapsObject(MapsObjectId('id4')); final Set previous = Set.from([to1, to2, to3]); @@ -40,8 +40,10 @@ void main() { final TestMapsObjectUpdate updates = TestMapsObjectUpdate.from(previous, current); - final Set> toRemove = Set.from( - >[MapsObjectId('id1')]); + final Set> toRemove = + Set.from(>[ + const MapsObjectId('id1') + ]); expect(updates.objectIdsToRemove, toRemove); final Set toAdd = Set.from([to4]); @@ -53,15 +55,15 @@ void main() { }); test('toJson', () async { - final TestMapsObject to1 = + const TestMapsObject to1 = TestMapsObject(MapsObjectId('id1')); - final TestMapsObject to2 = + const TestMapsObject to2 = TestMapsObject(MapsObjectId('id2')); - final TestMapsObject to3 = + const TestMapsObject to3 = TestMapsObject(MapsObjectId('id3')); - final TestMapsObject to3Changed = + const TestMapsObject to3Changed = TestMapsObject(MapsObjectId('id3'), data: 2); - final TestMapsObject to4 = + const TestMapsObject to4 = TestMapsObject(MapsObjectId('id4')); final Set previous = Set.from([to1, to2, to3]); @@ -81,15 +83,15 @@ void main() { }); test('equality', () async { - final TestMapsObject to1 = + const TestMapsObject to1 = TestMapsObject(MapsObjectId('id1')); - final TestMapsObject to2 = + const TestMapsObject to2 = TestMapsObject(MapsObjectId('id2')); - final TestMapsObject to3 = + const TestMapsObject to3 = TestMapsObject(MapsObjectId('id3')); - final TestMapsObject to3Changed = + const TestMapsObject to3Changed = TestMapsObject(MapsObjectId('id3'), data: 2); - final TestMapsObject to4 = + const TestMapsObject to4 = TestMapsObject(MapsObjectId('id4')); final Set previous = Set.from([to1, to2, to3]); @@ -109,15 +111,15 @@ void main() { }); test('hashCode', () async { - final TestMapsObject to1 = + const TestMapsObject to1 = TestMapsObject(MapsObjectId('id1')); - final TestMapsObject to2 = + const TestMapsObject to2 = TestMapsObject(MapsObjectId('id2')); - final TestMapsObject to3 = + const TestMapsObject to3 = TestMapsObject(MapsObjectId('id3')); - final TestMapsObject to3Changed = + const TestMapsObject to3Changed = TestMapsObject(MapsObjectId('id3'), data: 2); - final TestMapsObject to4 = + const TestMapsObject to4 = TestMapsObject(MapsObjectId('id4')); final Set previous = Set.from([to1, to2, to3]); @@ -134,15 +136,15 @@ void main() { }); test('toString', () async { - final TestMapsObject to1 = + const TestMapsObject to1 = TestMapsObject(MapsObjectId('id1')); - final TestMapsObject to2 = + const TestMapsObject to2 = TestMapsObject(MapsObjectId('id2')); - final TestMapsObject to3 = + const TestMapsObject to3 = TestMapsObject(MapsObjectId('id3')); - final TestMapsObject to3Changed = + const TestMapsObject to3Changed = TestMapsObject(MapsObjectId('id3'), data: 2); - final TestMapsObject to4 = + const TestMapsObject to4 = TestMapsObject(MapsObjectId('id4')); final Set previous = Set.from([to1, to2, to3]); 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 e15c73f08a54..360d86617754 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 @@ -3,13 +3,14 @@ // 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'; +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 { - TestMapsObject(this.mapsId, {this.data = 1}); + const TestMapsObject(this.mapsId, {this.data = 1}); final MapsObjectId mapsId; 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 87380fdd651b..992438fafef1 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 @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:ui' show hashValues; + import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; @@ -11,22 +12,22 @@ void main() { group('tile overlay id tests', () { test('equality', () async { - final TileOverlayId id1 = TileOverlayId('1'); - final TileOverlayId id2 = TileOverlayId('1'); - final TileOverlayId id3 = TileOverlayId('2'); + const TileOverlayId id1 = TileOverlayId('1'); + const TileOverlayId id2 = TileOverlayId('1'); + const TileOverlayId id3 = TileOverlayId('2'); expect(id1, id2); expect(id1, isNot(id3)); }); test('toString', () async { - final TileOverlayId id1 = TileOverlayId('1'); + const TileOverlayId id1 = TileOverlayId('1'); expect(id1.toString(), 'TileOverlayId(1)'); }); }); group('tile overlay tests', () { test('toJson returns correct format', () async { - final TileOverlay tileOverlay = TileOverlay( + const TileOverlay tileOverlay = TileOverlay( tileOverlayId: TileOverlayId('id'), fadeIn: false, tileProvider: null, @@ -48,16 +49,16 @@ void main() { test('invalid transparency throws', () async { expect( () => TileOverlay( - tileOverlayId: TileOverlayId('id1'), transparency: -0.1), + tileOverlayId: const TileOverlayId('id1'), transparency: -0.1), throwsAssertionError); expect( () => TileOverlay( - tileOverlayId: TileOverlayId('id2'), transparency: 1.2), + tileOverlayId: const TileOverlayId('id2'), transparency: 1.2), throwsAssertionError); }); test('equality', () async { - final TileOverlay tileOverlay1 = TileOverlay( + const TileOverlay tileOverlay1 = TileOverlay( tileOverlayId: TileOverlayId('id1'), fadeIn: false, tileProvider: null, @@ -65,7 +66,7 @@ void main() { zIndex: 1, visible: false, tileSize: 128); - final TileOverlay tileOverlay2 = TileOverlay( + const TileOverlay tileOverlay2 = TileOverlay( tileOverlayId: TileOverlayId('id1'), fadeIn: false, tileProvider: null, @@ -73,7 +74,7 @@ void main() { zIndex: 1, visible: false, tileSize: 128); - final TileOverlay tileOverlay3 = TileOverlay( + const TileOverlay tileOverlay3 = TileOverlay( tileOverlayId: TileOverlayId('id2'), fadeIn: false, tileProvider: null, @@ -86,8 +87,8 @@ void main() { }); test('hashCode', () async { - TileOverlayId id = TileOverlayId('id1'); - final TileOverlay tileOverlay = TileOverlay( + const TileOverlayId id = TileOverlayId('id1'); + const TileOverlay tileOverlay = TileOverlay( tileOverlayId: id, fadeIn: false, tileProvider: null, 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 f622ca5213ef..0db7d9d33324 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 @@ -3,22 +3,23 @@ // found in the LICENSE file. import 'dart:ui' show hashValues, hashList; + import 'package:flutter_test/flutter_test.dart'; -import 'package:google_maps_flutter_platform_interface/src/types/utils/tile_overlay.dart'; -import 'package:google_maps_flutter_platform_interface/src/types/tile_overlay_updates.dart'; import 'package:google_maps_flutter_platform_interface/src/types/tile_overlay.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/tile_overlay_updates.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/utils/tile_overlay.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); group('tile overlay updates tests', () { test('Correctly set toRemove, toAdd and toChange', () async { - final TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); - final TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); - final TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); - final TileOverlay to3Changed = + const TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); + const TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); + const TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); + const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); - final TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); + const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); final Set previous = Set.from([to1, to2, to3]); final Set current = Set.from([to2, to3Changed, to4]); @@ -26,7 +27,7 @@ void main() { TileOverlayUpdates.from(previous, current); final Set toRemove = - Set.from([TileOverlayId('id1')]); + Set.from([const TileOverlayId('id1')]); expect(updates.tileOverlayIdsToRemove, toRemove); final Set toAdd = Set.from([to4]); @@ -37,12 +38,12 @@ void main() { }); test('toJson', () async { - final TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); - final TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); - final TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); - final TileOverlay to3Changed = + const TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); + const TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); + const TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); + const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); - final TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); + const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); final Set previous = Set.from([to1, to2, to3]); final Set current = Set.from([to2, to3Changed, to4]); @@ -61,12 +62,12 @@ void main() { }); test('equality', () async { - final TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); - final TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); - final TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); - final TileOverlay to3Changed = + const TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); + const TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); + const TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); + const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); - final TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); + const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); final Set previous = Set.from([to1, to2, to3]); final Set current1 = Set.from([to2, to3Changed, to4]); @@ -84,12 +85,12 @@ void main() { }); test('hashCode', () async { - final TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); - final TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); - final TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); - final TileOverlay to3Changed = + const TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); + const TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); + const TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); + const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); - final TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); + const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); final Set previous = Set.from([to1, to2, to3]); final Set current = Set.from([to2, to3Changed, to4]); @@ -104,12 +105,12 @@ void main() { }); test('toString', () async { - final TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); - final TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); - final TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); - final TileOverlay to3Changed = + const TileOverlay to1 = TileOverlay(tileOverlayId: TileOverlayId('id1')); + const TileOverlay to2 = TileOverlay(tileOverlayId: TileOverlayId('id2')); + const TileOverlay to3 = TileOverlay(tileOverlayId: TileOverlayId('id3')); + const TileOverlay to3Changed = TileOverlay(tileOverlayId: TileOverlayId('id3'), transparency: 0.5); - final TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); + const TileOverlay to4 = TileOverlay(tileOverlayId: TileOverlayId('id4')); final Set previous = Set.from([to1, to2, to3]); final Set current = Set.from([to2, to3Changed, to4]); 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 3e0fe99ec18c..d985ac30136e 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 @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:typed_data'; + import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; @@ -22,7 +23,7 @@ void main() { }); test('toJson handles null data', () async { - final Tile tile = Tile(0, 0, null); + const Tile tile = Tile(0, 0, null); final Object json = tile.toJson(); expect(json, { 'width': 0, From d443a59b14ec654692b82bd5b05e75f45ca2cf55 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Wed, 17 Mar 2021 16:25:28 -0400 Subject: [PATCH 2/3] Prep for alignment with Flutter analysis options (#3703) Renames the old analysis_options.yaml to analysis_options_legacy.yaml, replacing it with a slightly modified copy of flutter/flutter's analysis options. Each plugins has a temporary local analysis_options.yaml that points to the legacy version. This allows for inceremental conversion on a per-plugin basis, which should make the problem more tractable. Since this hasn't yet been enabled for any packages, it's likely that as it is we'll find a few local modification we need to make to the root analysis_options (e.g., things that conflict with 'dart format'). Part of https://github.com/flutter/flutter/issues/76229 --- analysis_options.yaml | 242 +++++++++++++++++- analysis_options_legacy.yaml | 13 + .../analysis_options.yaml | 1 + packages/android_intent/analysis_options.yaml | 1 + packages/battery/analysis_options.yaml | 1 + packages/camera/analysis_options.yaml | 1 + packages/connectivity/analysis_options.yaml | 1 + packages/cross_file/analysis_options.yaml | 1 + packages/device_info/analysis_options.yaml | 1 + packages/e2e/analysis_options.yaml | 1 + packages/espresso/analysis_options.yaml | 1 + packages/file_selector/analysis_options.yaml | 1 + .../analysis_options.yaml | 1 + .../google_maps_flutter/analysis_options.yaml | 1 + packages/google_sign_in/analysis_options.yaml | 1 + packages/image_picker/analysis_options.yaml | 1 + .../in_app_purchase/analysis_options.yaml | 1 + .../integration_test/analysis_options.yaml | 1 + .../ios_platform_images/analysis_options.yaml | 1 + packages/local_auth/analysis_options.yaml | 1 + packages/package_info/analysis_options.yaml | 1 + packages/path_provider/analysis_options.yaml | 1 + .../analysis_options.yaml | 1 + packages/quick_actions/analysis_options.yaml | 1 + packages/sensors/analysis_options.yaml | 1 + packages/share/analysis_options.yaml | 1 + .../shared_preferences/analysis_options.yaml | 1 + packages/url_launcher/analysis_options.yaml | 1 + packages/video_player/analysis_options.yaml | 1 + .../webview_flutter/analysis_options.yaml | 1 + .../wifi_info_flutter/analysis_options.yaml | 1 + script/tool/analysis_options.yaml | 1 + 32 files changed, 280 insertions(+), 5 deletions(-) create mode 100644 analysis_options_legacy.yaml create mode 100644 packages/android_alarm_manager/analysis_options.yaml create mode 100644 packages/android_intent/analysis_options.yaml create mode 100644 packages/battery/analysis_options.yaml create mode 100644 packages/camera/analysis_options.yaml create mode 100644 packages/connectivity/analysis_options.yaml create mode 100644 packages/cross_file/analysis_options.yaml create mode 100644 packages/device_info/analysis_options.yaml create mode 100644 packages/e2e/analysis_options.yaml create mode 100644 packages/espresso/analysis_options.yaml create mode 100644 packages/file_selector/analysis_options.yaml create mode 100644 packages/flutter_plugin_android_lifecycle/analysis_options.yaml create mode 100644 packages/google_maps_flutter/analysis_options.yaml create mode 100644 packages/google_sign_in/analysis_options.yaml create mode 100644 packages/image_picker/analysis_options.yaml create mode 100644 packages/in_app_purchase/analysis_options.yaml create mode 100644 packages/integration_test/analysis_options.yaml create mode 100644 packages/ios_platform_images/analysis_options.yaml create mode 100644 packages/local_auth/analysis_options.yaml create mode 100644 packages/package_info/analysis_options.yaml create mode 100644 packages/path_provider/analysis_options.yaml create mode 100644 packages/plugin_platform_interface/analysis_options.yaml create mode 100644 packages/quick_actions/analysis_options.yaml create mode 100644 packages/sensors/analysis_options.yaml create mode 100644 packages/share/analysis_options.yaml create mode 100644 packages/shared_preferences/analysis_options.yaml create mode 100644 packages/url_launcher/analysis_options.yaml create mode 100644 packages/video_player/analysis_options.yaml create mode 100644 packages/webview_flutter/analysis_options.yaml create mode 100644 packages/wifi_info_flutter/analysis_options.yaml create mode 100644 script/tool/analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml index 2b62a6a9e2b9..858560e41e8a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,13 +1,245 @@ -include: package:pedantic/analysis_options.1.8.0.yaml +# This is a copy (as of March 2021) of flutter/flutter's analysis_options file, +# 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. +# +# Until there are meta linter rules, each desired lint must be explicitly enabled. +# See: https://github.com/dart-lang/linter/issues/288 +# +# For a list of lints, see: http://dart-lang.github.io/linter/lints/ +# See the configuration guide for more +# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer +# +# There are other similar analysis options files in the flutter repos, +# which should be kept in sync with this file: +# +# - analysis_options.yaml (this file) +# - packages/flutter/lib/analysis_options_user.yaml +# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml +# - https://github.com/flutter/engine/blob/master/analysis_options.yaml +# +# This file contains the analysis options used by Flutter tools, such as IntelliJ, +# Android Studio, and the `flutter analyze` command. + analyzer: + strong-mode: + implicit-casts: false + implicit-dynamic: false + errors: + # treat missing required parameters as a warning (not a hint) + missing_required_param: warning + # treat missing returns as a warning (not a hint) + missing_return: warning + # allow having TODOs in the code + todo: ignore + # allow self-reference to deprecated members (we do this because otherwise we have + # to annotate every member in every test, assert, etc, when we deprecate something) + deprecated_member_use_from_same_package: ignore + # Ignore analyzer hints for updating pubspecs when using Future or + # Stream and not importing dart:async + # Please see https://github.com/flutter/flutter/pull/24528 for details. + sdk_version_async_exported_from_core: ignore + ### Local flutter/plugins changes ### + # Allow null checks for as long as mixed mode is officially supported. + unnecessary_null_comparison: false + always_require_non_null_named_parameters: false # not needed with nnbd exclude: # Ignore generated files - '**/*.g.dart' - 'lib/src/generated/*.dart' - '**/*.mocks.dart' # Mockito @GenerateMocks - 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 + # these rules are documented on and in the same order as + # the Dart Lint rules page to make maintenance easier + # https://github.com/dart-lang/linter/blob/master/example/all.yaml + - always_declare_return_types + - always_put_control_body_on_new_line + # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219 + - always_require_non_null_named_parameters + - always_specify_types + # - always_use_package_imports # we do this commonly + - annotate_overrides + # - avoid_annotating_with_dynamic # conflicts with always_specify_types + # - avoid_as # required for implicit-casts: true + - avoid_bool_literals_in_conditional_expressions + # - avoid_catches_without_on_clauses # we do this commonly + # - avoid_catching_errors # we do this commonly + - avoid_classes_with_only_static_members + # - avoid_double_and_int_checks # only useful when targeting JS runtime + - avoid_empty_else + - avoid_equals_and_hash_code_on_mutable_classes + # - avoid_escaping_inner_quotes # not yet tested + - avoid_field_initializers_in_const_classes + - avoid_function_literals_in_foreach_calls + # - avoid_implementing_value_types # not yet tested + - avoid_init_to_null + # - avoid_js_rounded_ints # only useful when targeting JS runtime + - avoid_null_checks_in_equality_operators + # - avoid_positional_boolean_parameters # not yet tested + # - avoid_print # not yet tested + # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356) + # - avoid_redundant_argument_values # not yet tested + - avoid_relative_lib_imports + - avoid_renaming_method_parameters + - avoid_return_types_on_setters + # - avoid_returning_null # there are plenty of valid reasons to return null + # - avoid_returning_null_for_future # not yet tested + - avoid_returning_null_for_void + # - avoid_returning_this # there are plenty of valid reasons to return this + # - avoid_setters_without_getters # not yet tested + - avoid_shadowing_type_parameters + - avoid_single_cascade_in_expression_statements + - avoid_slow_async_io + # - avoid_type_to_string # we do this commonly + - avoid_types_as_parameter_names + # - avoid_types_on_closure_parameters # conflicts with always_specify_types + # - avoid_unnecessary_containers # not yet tested + - avoid_unused_constructor_parameters + - avoid_void_async + # - avoid_web_libraries_in_flutter # not yet tested + - await_only_futures + - camel_case_extensions + - camel_case_types + - cancel_subscriptions + # - cascade_invocations # not yet tested + - cast_nullable_to_non_nullable + # - close_sinks # not reliable enough + # - comment_references # blocked on https://github.com/flutter/flutter/issues/20765 + # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204 + - control_flow_in_finally + # - curly_braces_in_flow_control_structures # not required by flutter style + # - diagnostic_describe_all_properties # not yet tested + - directives_ordering + # - do_not_use_environment # we do this commonly + - empty_catches + - empty_constructor_bodies + - empty_statements + - exhaustive_cases + # - file_names # not yet tested + - flutter_style_todos + - hash_and_equals + - implementation_imports + # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811 + - iterable_contains_unrelated_type + # - join_return_with_assignment # not required by flutter style + - leading_newlines_in_multiline_strings + - library_names + - library_prefixes + # - lines_longer_than_80_chars # not required by flutter style + - list_remove_unrelated_type + # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181 + # - missing_whitespace_between_adjacent_strings # not yet tested + - no_adjacent_strings_in_list + # - no_default_cases # too many false positives + - no_duplicate_case_values + - no_logic_in_create_state + # - no_runtimeType_toString # ok in tests; we enable this only in packages/ + - non_constant_identifier_names + - null_check_on_nullable_type_parameter + # - null_closures # not required by flutter style + # - omit_local_variable_types # opposite of always_specify_types + # - one_member_abstracts # too many false positives + # - only_throw_errors # https://github.com/flutter/flutter/issues/5792 + - overridden_fields + - package_api_docs + # - package_names # non conforming packages in sdk + - package_prefixed_library_names + # - parameter_assignments # we do this commonly + - prefer_adjacent_string_concatenation + - prefer_asserts_in_initializer_lists + # - prefer_asserts_with_message # not required by flutter style + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_const_constructors + - prefer_const_constructors_in_immutables + - prefer_const_declarations + - prefer_const_literals_to_create_immutables + # - prefer_constructors_over_static_methods # far too many false positives + - prefer_contains + # - prefer_double_quotes # opposite of prefer_single_quotes + - prefer_equal_for_default_values + # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods + - prefer_final_fields + - prefer_final_in_for_each + - prefer_final_locals + - prefer_for_elements_to_map_fromIterable + - prefer_foreach + # - prefer_function_declarations_over_variables # not yet tested + - prefer_generic_function_type_aliases + - prefer_if_elements_to_conditional_expressions + - prefer_if_null_operators + - prefer_initializing_formals + - prefer_inlined_adds + # - prefer_int_literals # not yet tested + # - prefer_interpolation_to_compose_strings # not yet tested + - prefer_is_empty + - prefer_is_not_empty + - prefer_is_not_operator + - prefer_iterable_whereType + # - prefer_mixin # https://github.com/dart-lang/language/issues/32 + # - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932 + # - prefer_relative_imports # not yet tested + - prefer_single_quotes + - prefer_spread_collections + - prefer_typing_uninitialized_variables + - prefer_void_to_null + # - provide_deprecation_message # not yet tested + # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml + - recursive_getters + # - sized_box_for_whitespace # not yet tested + - slash_for_doc_comments + # - sort_child_properties_last # not yet tested + - sort_constructors_first + # - sort_pub_dependencies # prevents separating pinned transitive dependencies + - sort_unnamed_constructors_first + - test_types_in_equals + - throw_in_finally + - tighten_type_of_initializing_formals + # - type_annotate_public_apis # subset of always_specify_types + - type_init_formals + # - unawaited_futures # too many false positives + # - unnecessary_await_in_return # not yet tested + - unnecessary_brace_in_string_interps + - unnecessary_const + # - unnecessary_final # conflicts with prefer_final_locals + - unnecessary_getters_setters + # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498 + - unnecessary_new + - unnecessary_null_aware_assignments + # - unnecessary_null_checks # not yet tested + - unnecessary_null_in_if_null_operators + - unnecessary_nullable_for_final_variable_declarations + - unnecessary_overrides + - unnecessary_parenthesis + # - unnecessary_raw_strings # not yet tested + - unnecessary_statements + - unnecessary_string_escapes + - unnecessary_string_interpolations + - unnecessary_this + - unrelated_type_equality_checks + # - unsafe_html # not yet tested + - use_full_hex_values_for_flutter_colors + # - use_function_type_syntax_for_parameters # not yet tested + - use_is_even_rather_than_modulo + # - use_key_in_widget_constructors # not yet tested + - use_late_for_private_fields_and_variables + - use_raw_strings + - use_rethrow_when_possible + # - use_setters_to_change_properties # not yet tested + # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182 + # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review + - valid_regexps + - void_checks + ### Local flutter/plugins changes ### + # These are from flutter/flutter/packages, so will need to be preserved + # separately when moving to a shared file. + - no_runtimeType_toString # use objectRuntimeType from package:foundation + - public_member_api_docs # see https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#documentation-dartdocs-javadocs-etc diff --git a/analysis_options_legacy.yaml b/analysis_options_legacy.yaml new file mode 100644 index 000000000000..2b62a6a9e2b9 --- /dev/null +++ b/analysis_options_legacy.yaml @@ -0,0 +1,13 @@ +include: package:pedantic/analysis_options.1.8.0.yaml +analyzer: + exclude: + # Ignore generated files + - '**/*.g.dart' + - 'lib/src/generated/*.dart' + - '**/*.mocks.dart' # Mockito @GenerateMocks + 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/android_alarm_manager/analysis_options.yaml b/packages/android_alarm_manager/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/android_alarm_manager/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/android_intent/analysis_options.yaml b/packages/android_intent/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/android_intent/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/battery/analysis_options.yaml b/packages/battery/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/battery/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/camera/analysis_options.yaml b/packages/camera/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/camera/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/connectivity/analysis_options.yaml b/packages/connectivity/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/connectivity/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/cross_file/analysis_options.yaml b/packages/cross_file/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/cross_file/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/device_info/analysis_options.yaml b/packages/device_info/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/device_info/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/e2e/analysis_options.yaml b/packages/e2e/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/e2e/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/espresso/analysis_options.yaml b/packages/espresso/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/espresso/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/file_selector/analysis_options.yaml b/packages/file_selector/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/file_selector/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/flutter_plugin_android_lifecycle/analysis_options.yaml b/packages/flutter_plugin_android_lifecycle/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/flutter_plugin_android_lifecycle/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/google_maps_flutter/analysis_options.yaml b/packages/google_maps_flutter/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/google_maps_flutter/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/google_sign_in/analysis_options.yaml b/packages/google_sign_in/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/google_sign_in/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/image_picker/analysis_options.yaml b/packages/image_picker/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/image_picker/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/in_app_purchase/analysis_options.yaml b/packages/in_app_purchase/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/in_app_purchase/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/integration_test/analysis_options.yaml b/packages/integration_test/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/integration_test/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/ios_platform_images/analysis_options.yaml b/packages/ios_platform_images/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/ios_platform_images/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/local_auth/analysis_options.yaml b/packages/local_auth/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/local_auth/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/package_info/analysis_options.yaml b/packages/package_info/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/package_info/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/path_provider/analysis_options.yaml b/packages/path_provider/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/path_provider/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/plugin_platform_interface/analysis_options.yaml b/packages/plugin_platform_interface/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/plugin_platform_interface/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/quick_actions/analysis_options.yaml b/packages/quick_actions/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/quick_actions/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/sensors/analysis_options.yaml b/packages/sensors/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/sensors/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/share/analysis_options.yaml b/packages/share/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/share/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/shared_preferences/analysis_options.yaml b/packages/shared_preferences/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/shared_preferences/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/url_launcher/analysis_options.yaml b/packages/url_launcher/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/url_launcher/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/video_player/analysis_options.yaml b/packages/video_player/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/video_player/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/webview_flutter/analysis_options.yaml b/packages/webview_flutter/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/webview_flutter/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/packages/wifi_info_flutter/analysis_options.yaml b/packages/wifi_info_flutter/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/packages/wifi_info_flutter/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml diff --git a/script/tool/analysis_options.yaml b/script/tool/analysis_options.yaml new file mode 100644 index 000000000000..cda4f6e153e6 --- /dev/null +++ b/script/tool/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options_legacy.yaml From a8551330e9939da054b24db03f15337cae9af753 Mon Sep 17 00:00:00 2001 From: Guilherme Girotto Date: Thu, 18 Mar 2021 13:06:03 -0300 Subject: [PATCH 3/3] [google_sign_in] Adds support to send `clientId` as a parameter (#3640) --- .../google_sign_in/CHANGELOG.md | 5 +++++ .../googlesignin/GoogleSignInPlugin.java | 20 +++++++++++++++---- .../google_sign_in/example/lib/main.dart | 2 ++ .../ios/Classes/FLTGoogleSignInPlugin.m | 10 +++++++++- .../google_sign_in/pubspec.yaml | 4 ++-- .../test/google_sign_in_test.dart | 19 ++++++++++++++++++ 6 files changed, 53 insertions(+), 7 deletions(-) diff --git a/packages/google_sign_in/google_sign_in/CHANGELOG.md b/packages/google_sign_in/google_sign_in/CHANGELOG.md index 57d1c9be3743..429b07b47472 100644 --- a/packages/google_sign_in/google_sign_in/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in/CHANGELOG.md @@ -1,3 +1,8 @@ +## 5.0.1 + +* Update platforms `init` function to prioritize `clientId` property when available; +* Updates `google_sign_in_platform_interface` version. + ## 5.0.0 * Migrate to null safety. diff --git a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index f6673e5d5978..eb3a3d0d91ec 100755 --- a/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -136,7 +136,8 @@ public void onMethodCall(MethodCall call, Result result) { String signInOption = call.argument("signInOption"); List requestedScopes = call.argument("scopes"); String hostedDomain = call.argument("hostedDomain"); - delegate.init(result, signInOption, requestedScopes, hostedDomain); + String clientId = call.argument("clientId"); + delegate.init(result, signInOption, requestedScopes, hostedDomain, clientId); break; case METHOD_SIGN_IN_SILENTLY: @@ -188,7 +189,11 @@ public void onMethodCall(MethodCall call, Result result) { public interface IDelegate { /** Initializes this delegate so that it is ready to perform other operations. */ public void init( - Result result, String signInOption, List requestedScopes, String hostedDomain); + Result result, + String signInOption, + List requestedScopes, + String hostedDomain, + String clientId); /** * Returns the account information for the user who is signed in to this app. If no user is @@ -309,7 +314,11 @@ private void checkAndSetPendingOperation(String method, Result result, Object da */ @Override public void init( - Result result, String signInOption, List requestedScopes, String hostedDomain) { + Result result, + String signInOption, + List requestedScopes, + String hostedDomain, + String clientId) { try { GoogleSignInOptions.Builder optionsBuilder; @@ -334,7 +343,10 @@ public void init( context .getResources() .getIdentifier("default_web_client_id", "string", context.getPackageName()); - if (clientIdIdentifier != 0) { + if (!Strings.isNullOrEmpty(clientId)) { + optionsBuilder.requestIdToken(clientId); + optionsBuilder.requestServerAuthCode(clientId); + } else if (clientIdIdentifier != 0) { optionsBuilder.requestIdToken(context.getString(clientIdIdentifier)); optionsBuilder.requestServerAuthCode(context.getString(clientIdIdentifier)); } diff --git a/packages/google_sign_in/google_sign_in/example/lib/main.dart b/packages/google_sign_in/google_sign_in/example/lib/main.dart index e003225af5cc..c87063297373 100755 --- a/packages/google_sign_in/google_sign_in/example/lib/main.dart +++ b/packages/google_sign_in/google_sign_in/example/lib/main.dart @@ -12,6 +12,8 @@ import 'package:flutter/material.dart'; import 'package:google_sign_in/google_sign_in.dart'; GoogleSignIn _googleSignIn = GoogleSignIn( + // Optional clientId + // clientId: '479882132969-9i9aqik3jfjd7qhci1nqf0bm2g71rm1u.apps.googleusercontent.com', scopes: [ 'email', 'https://www.googleapis.com/auth/contacts.readonly', diff --git a/packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m b/packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m index 660a32272f84..fdc6e31e9291 100644 --- a/packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m +++ b/packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m @@ -77,7 +77,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result ofType:@"plist"]; if (path) { NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; - [GIDSignIn sharedInstance].clientID = plist[kClientIdKey]; + BOOL hasDynamicClientId = + [[call.arguments valueForKey:@"clientId"] isKindOfClass:[NSString class]]; + + if (hasDynamicClientId) { + [GIDSignIn sharedInstance].clientID = [call.arguments valueForKey:@"clientId"]; + } else { + [GIDSignIn sharedInstance].clientID = plist[kClientIdKey]; + } + [GIDSignIn sharedInstance].serverClientID = plist[kServerClientIdKey]; [GIDSignIn sharedInstance].scopes = call.arguments[@"scopes"]; [GIDSignIn sharedInstance].hostedDomain = call.arguments[@"hostedDomain"]; diff --git a/packages/google_sign_in/google_sign_in/pubspec.yaml b/packages/google_sign_in/google_sign_in/pubspec.yaml index 06fa12c0f4c0..23f2588c8f90 100644 --- a/packages/google_sign_in/google_sign_in/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in/pubspec.yaml @@ -2,7 +2,7 @@ name: google_sign_in description: Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android and iOS. homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in -version: 5.0.0 +version: 5.0.1 flutter: plugin: @@ -16,7 +16,7 @@ flutter: default_package: google_sign_in_web dependencies: - google_sign_in_platform_interface: ^2.0.0 + google_sign_in_platform_interface: ^2.0.1 google_sign_in_web: ^0.10.0 flutter: sdk: flutter diff --git a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart index 79fa74ad1be1..4eb45a5dc38e 100755 --- a/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart +++ b/packages/google_sign_in/google_sign_in/test/google_sign_in_test.dart @@ -82,6 +82,25 @@ void main() { ); }); + test('signIn prioritize clientId parameter when available', () async { + final fakeClientId = 'fakeClientId'; + googleSignIn = GoogleSignIn(clientId: fakeClientId); + await googleSignIn.signIn(); + expect(googleSignIn.currentUser, isNotNull); + expect( + log, + [ + isMethodCall('init', arguments: { + 'signInOption': 'SignInOption.standard', + 'scopes': [], + 'hostedDomain': null, + 'clientId': fakeClientId, + }), + isMethodCall('signIn', arguments: null), + ], + ); + }); + test('signOut', () async { await googleSignIn.signOut(); expect(googleSignIn.currentUser, isNull);