Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit d7125cd

Browse files
authored
[google_maps_flutter_platform_interface] Mark constructors as const for ids (#3718)
1 parent 3222a3e commit d7125cd

17 files changed

+111
-101
lines changed

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.2
2+
3+
* Mark constructors for CameraUpdate, CircleId, MapsObjectId, MarkerId, PolygonId, PolylineId and TileOverlayId as const
4+
15
## 2.0.1
26

37
* Update platform_plugin_interface version requirement.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import 'dart:async';
66
import 'dart:typed_data';
77

8-
import 'package:flutter/material.dart';
98
import 'package:flutter/foundation.dart';
10-
import 'package:flutter/services.dart';
119
import 'package:flutter/gestures.dart';
12-
10+
import 'package:flutter/material.dart';
11+
import 'package:flutter/services.dart';
1312
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
1413
import 'package:stream_transform/stream_transform.dart';
14+
1515
import '../types/tile_overlay_updates.dart';
1616
import '../types/utils/tile_overlay.dart';
1717

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class CameraPosition {
109109
/// Defines a camera move, supporting absolute moves as well as moves relative
110110
/// the current position.
111111
class CameraUpdate {
112-
CameraUpdate._(this._json);
112+
const CameraUpdate._(this._json);
113113

114114
/// Returns a camera update that moves the camera to the specified position.
115115
static CameraUpdate newCameraPosition(CameraPosition cameraPosition) {
@@ -176,15 +176,15 @@ class CameraUpdate {
176176
///
177177
/// Equivalent to the result of calling `zoomBy(1.0)`.
178178
static CameraUpdate zoomIn() {
179-
return CameraUpdate._(<Object>['zoomIn']);
179+
return const CameraUpdate._(<Object>['zoomIn']);
180180
}
181181

182182
/// Returns a camera update that zooms the camera out, bringing the camera
183183
/// further away from the surface of the Earth.
184184
///
185185
/// Equivalent to the result of calling `zoomBy(-1.0)`.
186186
static CameraUpdate zoomOut() {
187-
return CameraUpdate._(<Object>['zoomOut']);
187+
return const CameraUpdate._(<Object>['zoomOut']);
188188
}
189189

190190
/// Returns a camera update that sets the camera zoom level.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/circle.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'types.dart';
1414
@immutable
1515
class CircleId extends MapsObjectId<Circle> {
1616
/// Creates an immutable identifier for a [Circle].
17-
CircleId(String value) : super(value);
17+
const CircleId(String value) : super(value);
1818
}
1919

2020
/// Draws a circle on the map.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/maps_object.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MapsObjectId<T> {
1414
/// Creates an immutable object representing a [T] among [GoogleMap] Ts.
1515
///
1616
/// An [AssertionError] will be thrown if [value] is null.
17-
MapsObjectId(this.value) : assert(value != null);
17+
const MapsObjectId(this.value) : assert(value != null);
1818

1919
/// The value of the id.
2020
final String value;

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/marker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class InfoWindow {
104104
@immutable
105105
class MarkerId extends MapsObjectId<Marker> {
106106
/// Creates an immutable identifier for a [Marker].
107-
MarkerId(String value) : super(value);
107+
const MarkerId(String value) : super(value);
108108
}
109109

110110
/// Marks a geographical location on the map.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'types.dart';
1515
@immutable
1616
class PolygonId extends MapsObjectId<Polygon> {
1717
/// Creates an immutable identifier for a [Polygon].
18-
PolygonId(String value) : super(value);
18+
const PolygonId(String value) : super(value);
1919
}
2020

2121
/// Draws a polygon through geographical locations on the map.
@@ -167,7 +167,7 @@ class Polygon implements MapsObject {
167167
fillColor == typedOther.fillColor &&
168168
geodesic == typedOther.geodesic &&
169169
listEquals(points, typedOther.points) &&
170-
DeepCollectionEquality().equals(holes, typedOther.holes) &&
170+
const DeepCollectionEquality().equals(holes, typedOther.holes) &&
171171
visible == typedOther.visible &&
172172
strokeColor == typedOther.strokeColor &&
173173
strokeWidth == typedOther.strokeWidth &&

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polyline.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PolylineId extends MapsObjectId<Polyline> {
1616
/// Creates an immutable object representing a [PolylineId] among [GoogleMap] polylines.
1717
///
1818
/// An [AssertionError] will be thrown if [value] is null.
19-
PolylineId(String value) : super(value);
19+
const PolylineId(String value) : super(value);
2020
}
2121

2222
/// Draws a line through geographical locations on the map.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/tile_overlay.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
// found in the LICENSE file.
44

55
import 'dart:ui' show hashValues;
6+
67
import 'package:flutter/foundation.dart';
8+
import 'package:meta/meta.dart' show immutable;
79

810
import 'types.dart';
9-
import 'package:meta/meta.dart' show immutable;
1011

1112
/// Uniquely identifies a [TileOverlay] among [GoogleMap] tile overlays.
1213
@immutable
1314
class TileOverlayId extends MapsObjectId<TileOverlay> {
1415
/// Creates an immutable identifier for a [TileOverlay].
15-
TileOverlayId(String value) : super(value);
16+
const TileOverlayId(String value) : super(value);
1617
}
1718

1819
/// A set of images which are displayed on top of the base map tiles.

packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A common platform interface for the google_maps_flutter plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 2.0.1
6+
version: 2.0.2
77

88
dependencies:
99
flutter:

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/camera_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
// found in the LICENSE file.
44

55
import 'package:flutter_test/flutter_test.dart';
6-
76
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
87

98
void main() {
109
TestWidgetsFlutterBinding.ensureInitialized();
1110

1211
test('toMap / fromMap', () {
13-
final cameraPosition = CameraPosition(
12+
const cameraPosition = CameraPosition(
1413
target: LatLng(10.0, 15.0), bearing: 0.5, tilt: 30.0, zoom: 1.5);
1514
// Cast to <dynamic, dynamic> to ensure that recreating from JSON, where
1615
// type information will have likely been lost, still works.

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_test.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ void main() {
1212
TestWidgetsFlutterBinding.ensureInitialized();
1313

1414
test('keyByMapsObjectId', () async {
15-
final MapsObjectId<TestMapsObject> id1 = MapsObjectId<TestMapsObject>('1');
16-
final MapsObjectId<TestMapsObject> id2 = MapsObjectId<TestMapsObject>('2');
17-
final MapsObjectId<TestMapsObject> id3 = MapsObjectId<TestMapsObject>('3');
18-
final TestMapsObject object1 = TestMapsObject(id1);
19-
final TestMapsObject object2 = TestMapsObject(id2, data: 2);
20-
final TestMapsObject object3 = TestMapsObject(id3);
15+
const MapsObjectId<TestMapsObject> id1 = MapsObjectId<TestMapsObject>('1');
16+
const MapsObjectId<TestMapsObject> id2 = MapsObjectId<TestMapsObject>('2');
17+
const MapsObjectId<TestMapsObject> id3 = MapsObjectId<TestMapsObject>('3');
18+
const TestMapsObject object1 = TestMapsObject(id1);
19+
const TestMapsObject object2 = TestMapsObject(id2, data: 2);
20+
const TestMapsObject object3 = TestMapsObject(id3);
2121
expect(
2222
keyByMapsObjectId(<TestMapsObject>{object1, object2, object3}),
2323
<MapsObjectId<TestMapsObject>, TestMapsObject>{
@@ -28,12 +28,12 @@ void main() {
2828
});
2929

3030
test('serializeMapsObjectSet', () async {
31-
final MapsObjectId<TestMapsObject> id1 = MapsObjectId<TestMapsObject>('1');
32-
final MapsObjectId<TestMapsObject> id2 = MapsObjectId<TestMapsObject>('2');
33-
final MapsObjectId<TestMapsObject> id3 = MapsObjectId<TestMapsObject>('3');
34-
final TestMapsObject object1 = TestMapsObject(id1);
35-
final TestMapsObject object2 = TestMapsObject(id2, data: 2);
36-
final TestMapsObject object3 = TestMapsObject(id3);
31+
const MapsObjectId<TestMapsObject> id1 = MapsObjectId<TestMapsObject>('1');
32+
const MapsObjectId<TestMapsObject> id2 = MapsObjectId<TestMapsObject>('2');
33+
const MapsObjectId<TestMapsObject> id3 = MapsObjectId<TestMapsObject>('3');
34+
const TestMapsObject object1 = TestMapsObject(id1);
35+
const TestMapsObject object2 = TestMapsObject(id2, data: 2);
36+
const TestMapsObject object3 = TestMapsObject(id3);
3737
expect(
3838
serializeMapsObjectSet(<TestMapsObject>{object1, object2, object3}),
3939
<Map<String, Object>>[

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/maps_object_updates_test.dart

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import 'dart:ui' show hashValues, hashList;
66

77
import 'package:flutter/rendering.dart';
88
import 'package:flutter_test/flutter_test.dart';
9-
import 'package:google_maps_flutter_platform_interface/src/types/utils/maps_object.dart';
10-
import 'package:google_maps_flutter_platform_interface/src/types/maps_object_updates.dart';
119
import 'package:google_maps_flutter_platform_interface/src/types/maps_object.dart';
10+
import 'package:google_maps_flutter_platform_interface/src/types/maps_object_updates.dart';
11+
import 'package:google_maps_flutter_platform_interface/src/types/utils/maps_object.dart';
1212

1313
import 'test_maps_object.dart';
1414

@@ -23,15 +23,15 @@ void main() {
2323

2424
group('tile overlay updates tests', () {
2525
test('Correctly set toRemove, toAdd and toChange', () async {
26-
final TestMapsObject to1 =
26+
const TestMapsObject to1 =
2727
TestMapsObject(MapsObjectId<TestMapsObject>('id1'));
28-
final TestMapsObject to2 =
28+
const TestMapsObject to2 =
2929
TestMapsObject(MapsObjectId<TestMapsObject>('id2'));
30-
final TestMapsObject to3 =
30+
const TestMapsObject to3 =
3131
TestMapsObject(MapsObjectId<TestMapsObject>('id3'));
32-
final TestMapsObject to3Changed =
32+
const TestMapsObject to3Changed =
3333
TestMapsObject(MapsObjectId<TestMapsObject>('id3'), data: 2);
34-
final TestMapsObject to4 =
34+
const TestMapsObject to4 =
3535
TestMapsObject(MapsObjectId<TestMapsObject>('id4'));
3636
final Set<TestMapsObject> previous =
3737
Set.from(<TestMapsObject>[to1, to2, to3]);
@@ -40,8 +40,10 @@ void main() {
4040
final TestMapsObjectUpdate updates =
4141
TestMapsObjectUpdate.from(previous, current);
4242

43-
final Set<MapsObjectId<TestMapsObject>> toRemove = Set.from(
44-
<MapsObjectId<TestMapsObject>>[MapsObjectId<TestMapsObject>('id1')]);
43+
final Set<MapsObjectId<TestMapsObject>> toRemove =
44+
Set.from(<MapsObjectId<TestMapsObject>>[
45+
const MapsObjectId<TestMapsObject>('id1')
46+
]);
4547
expect(updates.objectIdsToRemove, toRemove);
4648

4749
final Set<TestMapsObject> toAdd = Set.from(<TestMapsObject>[to4]);
@@ -53,15 +55,15 @@ void main() {
5355
});
5456

5557
test('toJson', () async {
56-
final TestMapsObject to1 =
58+
const TestMapsObject to1 =
5759
TestMapsObject(MapsObjectId<TestMapsObject>('id1'));
58-
final TestMapsObject to2 =
60+
const TestMapsObject to2 =
5961
TestMapsObject(MapsObjectId<TestMapsObject>('id2'));
60-
final TestMapsObject to3 =
62+
const TestMapsObject to3 =
6163
TestMapsObject(MapsObjectId<TestMapsObject>('id3'));
62-
final TestMapsObject to3Changed =
64+
const TestMapsObject to3Changed =
6365
TestMapsObject(MapsObjectId<TestMapsObject>('id3'), data: 2);
64-
final TestMapsObject to4 =
66+
const TestMapsObject to4 =
6567
TestMapsObject(MapsObjectId<TestMapsObject>('id4'));
6668
final Set<TestMapsObject> previous =
6769
Set.from(<TestMapsObject>[to1, to2, to3]);
@@ -81,15 +83,15 @@ void main() {
8183
});
8284

8385
test('equality', () async {
84-
final TestMapsObject to1 =
86+
const TestMapsObject to1 =
8587
TestMapsObject(MapsObjectId<TestMapsObject>('id1'));
86-
final TestMapsObject to2 =
88+
const TestMapsObject to2 =
8789
TestMapsObject(MapsObjectId<TestMapsObject>('id2'));
88-
final TestMapsObject to3 =
90+
const TestMapsObject to3 =
8991
TestMapsObject(MapsObjectId<TestMapsObject>('id3'));
90-
final TestMapsObject to3Changed =
92+
const TestMapsObject to3Changed =
9193
TestMapsObject(MapsObjectId<TestMapsObject>('id3'), data: 2);
92-
final TestMapsObject to4 =
94+
const TestMapsObject to4 =
9395
TestMapsObject(MapsObjectId<TestMapsObject>('id4'));
9496
final Set<TestMapsObject> previous =
9597
Set.from(<TestMapsObject>[to1, to2, to3]);
@@ -109,15 +111,15 @@ void main() {
109111
});
110112

111113
test('hashCode', () async {
112-
final TestMapsObject to1 =
114+
const TestMapsObject to1 =
113115
TestMapsObject(MapsObjectId<TestMapsObject>('id1'));
114-
final TestMapsObject to2 =
116+
const TestMapsObject to2 =
115117
TestMapsObject(MapsObjectId<TestMapsObject>('id2'));
116-
final TestMapsObject to3 =
118+
const TestMapsObject to3 =
117119
TestMapsObject(MapsObjectId<TestMapsObject>('id3'));
118-
final TestMapsObject to3Changed =
120+
const TestMapsObject to3Changed =
119121
TestMapsObject(MapsObjectId<TestMapsObject>('id3'), data: 2);
120-
final TestMapsObject to4 =
122+
const TestMapsObject to4 =
121123
TestMapsObject(MapsObjectId<TestMapsObject>('id4'));
122124
final Set<TestMapsObject> previous =
123125
Set.from(<TestMapsObject>[to1, to2, to3]);
@@ -134,15 +136,15 @@ void main() {
134136
});
135137

136138
test('toString', () async {
137-
final TestMapsObject to1 =
139+
const TestMapsObject to1 =
138140
TestMapsObject(MapsObjectId<TestMapsObject>('id1'));
139-
final TestMapsObject to2 =
141+
const TestMapsObject to2 =
140142
TestMapsObject(MapsObjectId<TestMapsObject>('id2'));
141-
final TestMapsObject to3 =
143+
const TestMapsObject to3 =
142144
TestMapsObject(MapsObjectId<TestMapsObject>('id3'));
143-
final TestMapsObject to3Changed =
145+
const TestMapsObject to3Changed =
144146
TestMapsObject(MapsObjectId<TestMapsObject>('id3'), data: 2);
145-
final TestMapsObject to4 =
147+
const TestMapsObject to4 =
146148
TestMapsObject(MapsObjectId<TestMapsObject>('id4'));
147149
final Set<TestMapsObject> previous =
148150
Set.from(<TestMapsObject>[to1, to2, to3]);

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/test_maps_object.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
// found in the LICENSE file.
44

55
import 'dart:ui' show hashValues;
6+
67
import 'package:flutter/rendering.dart';
7-
import 'package:google_maps_flutter_platform_interface/src/types/maps_object_updates.dart';
88
import 'package:google_maps_flutter_platform_interface/src/types/maps_object.dart';
9+
import 'package:google_maps_flutter_platform_interface/src/types/maps_object_updates.dart';
910

1011
/// A trivial TestMapsObject implementation for testing updates with.
1112
class TestMapsObject implements MapsObject {
12-
TestMapsObject(this.mapsId, {this.data = 1});
13+
const TestMapsObject(this.mapsId, {this.data = 1});
1314

1415
final MapsObjectId<TestMapsObject> mapsId;
1516

0 commit comments

Comments
 (0)