From 2189b35dc76fdeb0a5595f18167a75160cf858f4 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Wed, 25 Sep 2024 13:44:39 -0400 Subject: [PATCH 01/15] Convert Cap --- .../lib/src/types/cap.dart | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart index 3ca79583d12a..395411f2dd4e 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart @@ -6,10 +6,34 @@ import 'package:flutter/foundation.dart' show immutable; import 'types.dart'; +/// Enumeration of possible types of caps. +enum CapType { + /// Cap that is squared off exactly at the start or end vertex of a [Polyline] + /// with solid stroke pattern, equivalent to having no additional cap beyond + /// the start or end vertex. + butt('buttCap'), + /// Cap that is a semicircle with radius equal to half the stroke width, + /// centered at the start or end vertex of a [Polyline] with solid stroke + /// pattern. + round('roundCap'), + /// Cap that is squared off after extending half the stroke width beyond the + /// start or end vertex of a [Polyline] with solid stroke pattern. + square('squareCap'), + /// CustomCap with a bitmap overlay centered at the start or + /// end vertex of a [Polyline], orientated according to the direction of the line's + /// first or last edge and scaled with respect to the line's stroke width. + custom('customCap'); + + const CapType(this.name); + + /// Serialized String value of a cap type. + final String name; +} + /// Cap that can be applied at the start or end vertex of a [Polyline]. @immutable class Cap { - const Cap._(this._json); + const Cap._(this._type); /// Cap that is squared off exactly at the start or end vertex of a [Polyline] /// with solid stroke pattern, equivalent to having no additional cap beyond @@ -17,16 +41,16 @@ class Cap { /// /// This is the default cap type at start and end vertices of Polylines with /// solid stroke pattern. - static const Cap buttCap = Cap._(['buttCap']); + static const Cap buttCap = Cap._(CapType.butt); /// Cap that is a semicircle with radius equal to half the stroke width, /// centered at the start or end vertex of a [Polyline] with solid stroke /// pattern. - static const Cap roundCap = Cap._(['roundCap']); + static const Cap roundCap = Cap._(CapType.round); /// Cap that is squared off after extending half the stroke width beyond the /// start or end vertex of a [Polyline] with solid stroke pattern. - static const Cap squareCap = Cap._(['squareCap']); + static const Cap squareCap = Cap._(CapType.square); /// Constructs a new CustomCap with a bitmap overlay centered at the start or /// end vertex of a [Polyline], orientated according to the direction of the line's @@ -44,11 +68,32 @@ class Cap { double refWidth = 10, }) { assert(refWidth > 0.0); - return Cap._(['customCap', bitmapDescriptor.toJson(), refWidth]); + return CustomCap(bitmapDescriptor, refWidth); } - final Object _json; + final CapType _type; /// Converts this object to something serializable in JSON. - Object toJson() => _json; + Object toJson() => [_type.name]; +} + +/// CustomCap with a bitmap overlay centered at the start or +/// end vertex of a [Polyline], orientated according to the direction of the line's +/// first or last edge and scaled with respect to the line's stroke width. +class CustomCap extends Cap { + /// [bitmapDescriptor] must not be null. + /// + /// [refWidth] is the reference stroke width (in pixels) - the stroke width for which + /// the cap bitmap at its native dimension is designed. Must be positive. Default value + /// is 10 pixels. + const CustomCap(this.bitmapDescriptor, [this.refWidth = 10]) : super._(CapType.custom); + + /// Bitmap overlay centered at the start or end vertex of a [Polyline]. + final BitmapDescriptor bitmapDescriptor; + + /// Reference stroke width in pixels. + final double refWidth; + + @override + Object toJson() => [CapType.custom.name, bitmapDescriptor.toJson(), refWidth]; } From d79bbd13dd350db1b38bd5ebf04a8e7b52bac795 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Wed, 25 Sep 2024 13:47:41 -0400 Subject: [PATCH 02/15] Convert PatternItem --- .../lib/src/types/pattern_item.dart | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index 033210b8c5ae..198c1684661b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -4,20 +4,35 @@ import 'package:flutter/foundation.dart' show immutable; +/// Enumeration of types of pattern items. +enum PatternItemType { + /// A dot used in the stroke pattern for a [Polyline]. + dot('dot'), + /// A dash used in the stroke pattern for a [Polyline]. + dash('dash'), + /// A gap used in the stroke pattern for a [Polyline]. + gap('gap'); + + const PatternItemType(this.name); + + /// String name used for serialization. + final String name; +} + /// Item used in the stroke pattern for a Polyline. @immutable class PatternItem { - const PatternItem._(this._json); + const PatternItem._(this._type, [this._length]); /// A dot used in the stroke pattern for a [Polyline]. - static const PatternItem dot = PatternItem._(['dot']); + static const PatternItem dot = PatternItem._(PatternItemType.dot); /// A dash used in the stroke pattern for a [Polyline]. /// /// [length] has to be non-negative. static PatternItem dash(double length) { assert(length >= 0.0); - return PatternItem._(['dash', length]); + return PatternItem._(PatternItemType.dash, length); } /// A gap used in the stroke pattern for a [Polyline]. @@ -25,11 +40,12 @@ class PatternItem { /// [length] has to be non-negative. static PatternItem gap(double length) { assert(length >= 0.0); - return PatternItem._(['gap', length]); + return PatternItem._(PatternItemType.gap, length); } - final Object _json; + final PatternItemType _type; + final double? _length; /// Converts this object to something serializable in JSON. - Object toJson() => _json; + Object toJson() => [_type.name, if (_length != null) _length]; } From 486830f0f690a4e30bb369e76a4660077264b8dc Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Wed, 25 Sep 2024 13:52:02 -0400 Subject: [PATCH 03/15] Unit test Cap --- .../test/types/cap_test.dart | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/cap_test.dart diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/cap_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/cap_test.dart new file mode 100644 index 000000000000..a015e627e034 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/cap_test.dart @@ -0,0 +1,35 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + test('buttCap', () { + const Cap cap = Cap.buttCap; + expect(cap.toJson(), equals(['buttCap'])); + }); + + test('roundCap', () { + const Cap cap = Cap.roundCap; + expect(cap.toJson(), equals(['roundCap'])); + }); + + test('squareCap', () { + const Cap cap = Cap.squareCap; + expect(cap.toJson(), equals(['squareCap'])); + }); + + test('customCap', () { + final Cap cap = Cap.customCapFromBitmap(BitmapDescriptor.defaultMarker); + expect(cap.toJson(), equals(['customCap', ['defaultMarker'], 10.0])); + }); + + test('customCapWithWidth', () { + final Cap cap = Cap.customCapFromBitmap(BitmapDescriptor.defaultMarker, refWidth: 100); + expect(cap.toJson(), equals(['customCap', ['defaultMarker'], 100.0])); + }); +} From 6b8c0209bfeef62c4e233238a83a335119f558dc Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Wed, 25 Sep 2024 13:54:05 -0400 Subject: [PATCH 04/15] Unit test PatternItem --- .../test/types/pattern_item_test.dart | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart new file mode 100644 index 000000000000..a9c5c85a1b75 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart @@ -0,0 +1,25 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + test('dot', () { + const PatternItem item = PatternItem.dot; + expect(item.toJson(), equals(['dot'])); + }); + + test('dash', () { + final PatternItem item = PatternItem.dash(10.0); + expect(item.toJson(), equals(['dash', 10.0])); + }); + + test('gap', () { + final PatternItem item = PatternItem.gap(20.0); + expect(item.toJson(), equals(['gap', 20.0])); + }); +} \ No newline at end of file From e22fe575c18cff622daf5e9493f0e89bce2c2fc6 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Wed, 25 Sep 2024 13:54:28 -0400 Subject: [PATCH 05/15] Format --- .../lib/src/types/cap.dart | 9 +++++++-- .../lib/src/types/pattern_item.dart | 2 ++ .../test/types/cap_test.dart | 19 ++++++++++++++++--- .../test/types/pattern_item_test.dart | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart index 395411f2dd4e..087b8886b30b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart @@ -12,13 +12,16 @@ enum CapType { /// with solid stroke pattern, equivalent to having no additional cap beyond /// the start or end vertex. butt('buttCap'), + /// Cap that is a semicircle with radius equal to half the stroke width, /// centered at the start or end vertex of a [Polyline] with solid stroke /// pattern. round('roundCap'), + /// Cap that is squared off after extending half the stroke width beyond the /// start or end vertex of a [Polyline] with solid stroke pattern. square('squareCap'), + /// CustomCap with a bitmap overlay centered at the start or /// end vertex of a [Polyline], orientated according to the direction of the line's /// first or last edge and scaled with respect to the line's stroke width. @@ -86,7 +89,8 @@ class CustomCap extends Cap { /// [refWidth] is the reference stroke width (in pixels) - the stroke width for which /// the cap bitmap at its native dimension is designed. Must be positive. Default value /// is 10 pixels. - const CustomCap(this.bitmapDescriptor, [this.refWidth = 10]) : super._(CapType.custom); + const CustomCap(this.bitmapDescriptor, [this.refWidth = 10]) + : super._(CapType.custom); /// Bitmap overlay centered at the start or end vertex of a [Polyline]. final BitmapDescriptor bitmapDescriptor; @@ -95,5 +99,6 @@ class CustomCap extends Cap { final double refWidth; @override - Object toJson() => [CapType.custom.name, bitmapDescriptor.toJson(), refWidth]; + Object toJson() => + [CapType.custom.name, bitmapDescriptor.toJson(), refWidth]; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index 198c1684661b..88205c207043 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -8,8 +8,10 @@ import 'package:flutter/foundation.dart' show immutable; enum PatternItemType { /// A dot used in the stroke pattern for a [Polyline]. dot('dot'), + /// A dash used in the stroke pattern for a [Polyline]. dash('dash'), + /// A gap used in the stroke pattern for a [Polyline]. gap('gap'); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/cap_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/cap_test.dart index a015e627e034..bdd94018f9a4 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/cap_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/cap_test.dart @@ -25,11 +25,24 @@ void main() { test('customCap', () { final Cap cap = Cap.customCapFromBitmap(BitmapDescriptor.defaultMarker); - expect(cap.toJson(), equals(['customCap', ['defaultMarker'], 10.0])); + expect( + cap.toJson(), + equals([ + 'customCap', + ['defaultMarker'], + 10.0 + ])); }); test('customCapWithWidth', () { - final Cap cap = Cap.customCapFromBitmap(BitmapDescriptor.defaultMarker, refWidth: 100); - expect(cap.toJson(), equals(['customCap', ['defaultMarker'], 100.0])); + final Cap cap = + Cap.customCapFromBitmap(BitmapDescriptor.defaultMarker, refWidth: 100); + expect( + cap.toJson(), + equals([ + 'customCap', + ['defaultMarker'], + 100.0 + ])); }); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart index a9c5c85a1b75..4cf42dd49461 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart @@ -22,4 +22,4 @@ void main() { final PatternItem item = PatternItem.gap(20.0); expect(item.toJson(), equals(['gap', 20.0])); }); -} \ No newline at end of file +} From 644152fd74faebffd25513906c1cb2fa7229aa66 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Wed, 25 Sep 2024 13:55:05 -0400 Subject: [PATCH 06/15] Bump version --- .../google_maps_flutter_platform_interface/CHANGELOG.md | 5 +++++ .../google_maps_flutter_platform_interface/pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md index e39c3d5a5012..92cee39d993c 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,8 @@ +## 2.9.3 + +* Converts `PatternItem` to typesafe structure. +* Converts `Cap` to typesafe structure. + ## 2.9.2 * Corrects JSON tag for `CameraUpdateNewLatLngBounds`. 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 4a4489320fd0..cbd3a16f92a9 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/packages/tree/main/packages/google_maps_f 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.9.2 +version: 2.9.3 environment: sdk: ^3.3.0 From 1894614fea987e3a674c7a9cf1a4ba5de3cf84de Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Wed, 25 Sep 2024 16:41:48 -0400 Subject: [PATCH 07/15] PR Feedback --- .../lib/src/types/cap.dart | 32 +++++++++++-------- .../lib/src/types/pattern_item.dart | 32 ++++++++++++------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart index 087b8886b30b..ab638bcdc6ef 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart @@ -11,32 +11,34 @@ enum CapType { /// Cap that is squared off exactly at the start or end vertex of a [Polyline] /// with solid stroke pattern, equivalent to having no additional cap beyond /// the start or end vertex. - butt('buttCap'), + butt, /// Cap that is a semicircle with radius equal to half the stroke width, /// centered at the start or end vertex of a [Polyline] with solid stroke /// pattern. - round('roundCap'), + round, /// Cap that is squared off after extending half the stroke width beyond the /// start or end vertex of a [Polyline] with solid stroke pattern. - square('squareCap'), + square, /// CustomCap with a bitmap overlay centered at the start or /// end vertex of a [Polyline], orientated according to the direction of the line's /// first or last edge and scaled with respect to the line's stroke width. - custom('customCap'); - - const CapType(this.name); - - /// Serialized String value of a cap type. - final String name; + custom, } +String _capTypeToJson(CapType capType) => { + CapType.butt: 'buttCap', + CapType.round: 'roundCap', + CapType.square: 'squareCap', + CapType.custom: 'customCap', + }[capType]!; + /// Cap that can be applied at the start or end vertex of a [Polyline]. @immutable class Cap { - const Cap._(this._type); + const Cap._(this.type); /// Cap that is squared off exactly at the start or end vertex of a [Polyline] /// with solid stroke pattern, equivalent to having no additional cap beyond @@ -71,13 +73,15 @@ class Cap { double refWidth = 10, }) { assert(refWidth > 0.0); - return CustomCap(bitmapDescriptor, refWidth); + return CustomCap(bitmapDescriptor, refWidth: refWidth); } - final CapType _type; + /// The type of rendering used for the cap at a start or end vertex of a + /// [Polyline]. + final CapType type; /// Converts this object to something serializable in JSON. - Object toJson() => [_type.name]; + Object toJson() => [_capTypeToJson(type)]; } /// CustomCap with a bitmap overlay centered at the start or @@ -89,7 +93,7 @@ class CustomCap extends Cap { /// [refWidth] is the reference stroke width (in pixels) - the stroke width for which /// the cap bitmap at its native dimension is designed. Must be positive. Default value /// is 10 pixels. - const CustomCap(this.bitmapDescriptor, [this.refWidth = 10]) + const CustomCap(this.bitmapDescriptor, {this.refWidth = 10}) : super._(CapType.custom); /// Bitmap overlay centered at the start or end vertex of a [Polyline]. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index 88205c207043..a1ff3ab407da 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -7,24 +7,26 @@ import 'package:flutter/foundation.dart' show immutable; /// Enumeration of types of pattern items. enum PatternItemType { /// A dot used in the stroke pattern for a [Polyline]. - dot('dot'), + dot, /// A dash used in the stroke pattern for a [Polyline]. - dash('dash'), + dash, /// A gap used in the stroke pattern for a [Polyline]. - gap('gap'); - - const PatternItemType(this.name); - - /// String name used for serialization. - final String name; + gap, } +String _patternItemTypeToJson(PatternItemType itemType) => + const { + PatternItemType.dot: 'dot', + PatternItemType.dash: 'dash', + PatternItemType.gap: 'gap', + }[itemType]!; + /// Item used in the stroke pattern for a Polyline. @immutable class PatternItem { - const PatternItem._(this._type, [this._length]); + const PatternItem._(this.patternItemType, [this.length]); /// A dot used in the stroke pattern for a [Polyline]. static const PatternItem dot = PatternItem._(PatternItemType.dot); @@ -45,9 +47,15 @@ class PatternItem { return PatternItem._(PatternItemType.gap, length); } - final PatternItemType _type; - final double? _length; + /// The type of rendering used for an item in a pattern. + final PatternItemType patternItemType; + + /// The length in pixels of a dash or gap. + final double? length; /// Converts this object to something serializable in JSON. - Object toJson() => [_type.name, if (_length != null) _length]; + Object toJson() => [ + _patternItemTypeToJson(patternItemType), + if (length != null) length! + ]; } From a51e2ff0281891382a8eb89354ea970c7e69bef9 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Wed, 25 Sep 2024 16:47:09 -0400 Subject: [PATCH 08/15] Test fix --- .../lib/src/types/cap.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart index ab638bcdc6ef..cc0a326bf707 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart @@ -38,7 +38,7 @@ String _capTypeToJson(CapType capType) => { /// Cap that can be applied at the start or end vertex of a [Polyline]. @immutable class Cap { - const Cap._(this.type); + const Cap._(this.capType); /// Cap that is squared off exactly at the start or end vertex of a [Polyline] /// with solid stroke pattern, equivalent to having no additional cap beyond @@ -78,10 +78,10 @@ class Cap { /// The type of rendering used for the cap at a start or end vertex of a /// [Polyline]. - final CapType type; + final CapType capType; /// Converts this object to something serializable in JSON. - Object toJson() => [_capTypeToJson(type)]; + Object toJson() => [_capTypeToJson(capType)]; } /// CustomCap with a bitmap overlay centered at the start or @@ -104,5 +104,5 @@ class CustomCap extends Cap { @override Object toJson() => - [CapType.custom.name, bitmapDescriptor.toJson(), refWidth]; + [_capTypeToJson(capType), bitmapDescriptor.toJson(), refWidth]; } From b8173b2b9a91f3f1c6b06cefb87308d9dc292c34 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Mon, 30 Sep 2024 12:10:10 -0400 Subject: [PATCH 09/15] Convert map to switch --- .../lib/src/types/cap.dart | 12 ++++++------ .../lib/src/types/pattern_item.dart | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart index cc0a326bf707..8c092bb2288d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart @@ -28,12 +28,12 @@ enum CapType { custom, } -String _capTypeToJson(CapType capType) => { - CapType.butt: 'buttCap', - CapType.round: 'roundCap', - CapType.square: 'squareCap', - CapType.custom: 'customCap', - }[capType]!; +String _capTypeToJson(CapType capType) => switch (capType) { + CapType.butt => 'buttCap', + CapType.round => 'roundCap', + CapType.square => 'squareCap', + CapType.custom => 'customCap', +}; /// Cap that can be applied at the start or end vertex of a [Polyline]. @immutable diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index a1ff3ab407da..6076e8e3ed56 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -17,11 +17,11 @@ enum PatternItemType { } String _patternItemTypeToJson(PatternItemType itemType) => - const { - PatternItemType.dot: 'dot', - PatternItemType.dash: 'dash', - PatternItemType.gap: 'gap', - }[itemType]!; + switch (itemType) { + PatternItemType.dot => 'dot', + PatternItemType.dash => 'dash', + PatternItemType.gap => 'gap', + }; /// Item used in the stroke pattern for a Polyline. @immutable From d757868c4b6edf9ca122246fa3f7e092f9ef8fe8 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Mon, 30 Sep 2024 13:34:03 -0400 Subject: [PATCH 10/15] Format --- .../lib/src/types/cap.dart | 2 +- .../lib/src/types/pattern_item.dart | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart index 8c092bb2288d..0f1908eabc85 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart @@ -33,7 +33,7 @@ String _capTypeToJson(CapType capType) => switch (capType) { CapType.round => 'roundCap', CapType.square => 'squareCap', CapType.custom => 'customCap', -}; + }; /// Cap that can be applied at the start or end vertex of a [Polyline]. @immutable diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index 6076e8e3ed56..607cd784f56d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -16,8 +16,7 @@ enum PatternItemType { gap, } -String _patternItemTypeToJson(PatternItemType itemType) => - switch (itemType) { +String _patternItemTypeToJson(PatternItemType itemType) => switch (itemType) { PatternItemType.dot => 'dot', PatternItemType.dash => 'dash', PatternItemType.gap => 'gap', From f935885ed65c50c3b4bb7357bd3f4ffd022f5efe Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Tue, 1 Oct 2024 15:46:24 -0400 Subject: [PATCH 11/15] Divide PatternItem --- .../lib/src/types/pattern_item.dart | 21 ++++++++++++++----- .../pubspec.yaml | 2 +- .../test/types/pattern_item_test.dart | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index 607cd784f56d..cc468d224bfa 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -25,7 +25,7 @@ String _patternItemTypeToJson(PatternItemType itemType) => switch (itemType) { /// Item used in the stroke pattern for a Polyline. @immutable class PatternItem { - const PatternItem._(this.patternItemType, [this.length]); + const PatternItem._(this.patternItemType); /// A dot used in the stroke pattern for a [Polyline]. static const PatternItem dot = PatternItem._(PatternItemType.dot); @@ -35,7 +35,7 @@ class PatternItem { /// [length] has to be non-negative. static PatternItem dash(double length) { assert(length >= 0.0); - return PatternItem._(PatternItemType.dash, length); + return PatternItemWithLength._(patternItemType: PatternItemType.dash, length: length); } /// A gap used in the stroke pattern for a [Polyline]. @@ -43,18 +43,29 @@ class PatternItem { /// [length] has to be non-negative. static PatternItem gap(double length) { assert(length >= 0.0); - return PatternItem._(PatternItemType.gap, length); + return PatternItemWithLength._(patternItemType: PatternItemType.gap, length: length); } /// The type of rendering used for an item in a pattern. final PatternItemType patternItemType; + /// Converts this object to something serializable in JSON. + Object toJson() => [ + _patternItemTypeToJson(patternItemType), + ]; +} + +@immutable +class PatternItemWithLength extends PatternItem { + const PatternItemWithLength._({required PatternItemType patternItemType, required this.length}) : super._(patternItemType); + /// The length in pixels of a dash or gap. - final double? length; + final double length; /// Converts this object to something serializable in JSON. + @override Object toJson() => [ _patternItemTypeToJson(patternItemType), - if (length != null) length! + length, ]; } 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 cbd3a16f92a9..79fb73250712 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/packages/tree/main/packages/google_maps_f 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.9.3 +version: 2.9.4 environment: sdk: ^3.3.0 diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart index 4cf42dd49461..4f7ddffc730b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart @@ -15,11 +15,13 @@ void main() { test('dash', () { final PatternItem item = PatternItem.dash(10.0); + expect(item, isA()); expect(item.toJson(), equals(['dash', 10.0])); }); test('gap', () { final PatternItem item = PatternItem.gap(20.0); + expect(item, isA()); expect(item.toJson(), equals(['gap', 20.0])); }); } From 9b5c826741dddd37e6f716e4b24b43db81c48e24 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Tue, 1 Oct 2024 16:23:49 -0400 Subject: [PATCH 12/15] Doc comment --- .../lib/src/types/pattern_item.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index cc468d224bfa..423f017c4843 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -55,6 +55,7 @@ class PatternItem { ]; } +/// A pattern item with a length, i.e. a dash or gap. @immutable class PatternItemWithLength extends PatternItem { const PatternItemWithLength._({required PatternItemType patternItemType, required this.length}) : super._(patternItemType); From 54c3af53e5a665a70b1c5ebbcbe20c11a47a18ad Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Tue, 1 Oct 2024 17:11:43 -0400 Subject: [PATCH 13/15] Formatting --- .../lib/src/types/pattern_item.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index 423f017c4843..a584f2c38863 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -35,7 +35,8 @@ class PatternItem { /// [length] has to be non-negative. static PatternItem dash(double length) { assert(length >= 0.0); - return PatternItemWithLength._(patternItemType: PatternItemType.dash, length: length); + return PatternItemWithLength._( + patternItemType: PatternItemType.dash, length: length); } /// A gap used in the stroke pattern for a [Polyline]. @@ -43,7 +44,8 @@ class PatternItem { /// [length] has to be non-negative. static PatternItem gap(double length) { assert(length >= 0.0); - return PatternItemWithLength._(patternItemType: PatternItemType.gap, length: length); + return PatternItemWithLength._( + patternItemType: PatternItemType.gap, length: length); } /// The type of rendering used for an item in a pattern. @@ -58,7 +60,9 @@ class PatternItem { /// A pattern item with a length, i.e. a dash or gap. @immutable class PatternItemWithLength extends PatternItem { - const PatternItemWithLength._({required PatternItemType patternItemType, required this.length}) : super._(patternItemType); + const PatternItemWithLength._( + {required PatternItemType patternItemType, required this.length}) + : super._(patternItemType); /// The length in pixels of a dash or gap. final double length; From 91a4878344923f7382cc7e79d15c0804ce5c2681 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Fri, 4 Oct 2024 08:40:45 -0400 Subject: [PATCH 14/15] Refactor names --- .../lib/src/types/cap.dart | 8 ++++---- .../lib/src/types/pattern_item.dart | 16 ++++++++-------- .../test/types/pattern_item_test.dart | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart index 0f1908eabc85..27c3c95e0f1b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart @@ -38,7 +38,7 @@ String _capTypeToJson(CapType capType) => switch (capType) { /// Cap that can be applied at the start or end vertex of a [Polyline]. @immutable class Cap { - const Cap._(this.capType); + const Cap._(this.type); /// Cap that is squared off exactly at the start or end vertex of a [Polyline] /// with solid stroke pattern, equivalent to having no additional cap beyond @@ -78,10 +78,10 @@ class Cap { /// The type of rendering used for the cap at a start or end vertex of a /// [Polyline]. - final CapType capType; + final CapType type; /// Converts this object to something serializable in JSON. - Object toJson() => [_capTypeToJson(capType)]; + Object toJson() => [_capTypeToJson(type)]; } /// CustomCap with a bitmap overlay centered at the start or @@ -104,5 +104,5 @@ class CustomCap extends Cap { @override Object toJson() => - [_capTypeToJson(capType), bitmapDescriptor.toJson(), refWidth]; + [_capTypeToJson(type), bitmapDescriptor.toJson(), refWidth]; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart index a584f2c38863..90adfbc84c6a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/pattern_item.dart @@ -25,7 +25,7 @@ String _patternItemTypeToJson(PatternItemType itemType) => switch (itemType) { /// Item used in the stroke pattern for a Polyline. @immutable class PatternItem { - const PatternItem._(this.patternItemType); + const PatternItem._(this.type); /// A dot used in the stroke pattern for a [Polyline]. static const PatternItem dot = PatternItem._(PatternItemType.dot); @@ -35,7 +35,7 @@ class PatternItem { /// [length] has to be non-negative. static PatternItem dash(double length) { assert(length >= 0.0); - return PatternItemWithLength._( + return VariableLengthPatternItem._( patternItemType: PatternItemType.dash, length: length); } @@ -44,23 +44,23 @@ class PatternItem { /// [length] has to be non-negative. static PatternItem gap(double length) { assert(length >= 0.0); - return PatternItemWithLength._( + return VariableLengthPatternItem._( patternItemType: PatternItemType.gap, length: length); } /// The type of rendering used for an item in a pattern. - final PatternItemType patternItemType; + final PatternItemType type; /// Converts this object to something serializable in JSON. Object toJson() => [ - _patternItemTypeToJson(patternItemType), + _patternItemTypeToJson(type), ]; } /// A pattern item with a length, i.e. a dash or gap. @immutable -class PatternItemWithLength extends PatternItem { - const PatternItemWithLength._( +class VariableLengthPatternItem extends PatternItem { + const VariableLengthPatternItem._( {required PatternItemType patternItemType, required this.length}) : super._(patternItemType); @@ -70,7 +70,7 @@ class PatternItemWithLength extends PatternItem { /// Converts this object to something serializable in JSON. @override Object toJson() => [ - _patternItemTypeToJson(patternItemType), + _patternItemTypeToJson(type), length, ]; } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart index 4f7ddffc730b..ebd65a44f3ff 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/pattern_item_test.dart @@ -15,13 +15,13 @@ void main() { test('dash', () { final PatternItem item = PatternItem.dash(10.0); - expect(item, isA()); + expect(item, isA()); expect(item.toJson(), equals(['dash', 10.0])); }); test('gap', () { final PatternItem item = PatternItem.gap(20.0); - expect(item, isA()); + expect(item, isA()); expect(item.toJson(), equals(['gap', 20.0])); }); } From e1de2fac5c9bfeace639c35eb13150772e91f1b7 Mon Sep 17 00:00:00 2001 From: Yaakov Schectman Date: Fri, 4 Oct 2024 11:07:15 -0400 Subject: [PATCH 15/15] Document pixels --- .../lib/src/types/cap.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart index 27c3c95e0f1b..c67439e3e310 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cap.dart @@ -99,7 +99,8 @@ class CustomCap extends Cap { /// Bitmap overlay centered at the start or end vertex of a [Polyline]. final BitmapDescriptor bitmapDescriptor; - /// Reference stroke width in pixels. + /// Reference stroke width in screen pixels. See + /// https://developers.google.com/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/model/CustomCap#refWidth final double refWidth; @override