Skip to content

Commit 24594a0

Browse files
[google_maps_flutter_android] Convert PlatformPolyline.pattern to Pigeon (#7631)
Creates a structured `PlatformPatternItem` pigeon class to use in `PlatformPolyline`. flutter/flutter#154738 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [ ] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version [following repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style [exempt from CHANGELOG changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
1 parent a717b0e commit 24594a0

File tree

8 files changed

+366
-160
lines changed

8 files changed

+366
-160
lines changed

packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.14.7
2+
3+
* Adds `PlatformPatternItem` pigeon class to convert `PlatformPolyline.pattern`.
4+
15
## 2.14.6
26

37
* Converts 'PlatformCameraUpdate' to pigeon.

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static String interpretPolylineOptions(
711711
sink.setWidth(polyline.getWidth());
712712
sink.setZIndex(polyline.getZIndex());
713713
sink.setPoints(pointsFromPigeon(polyline.getPoints()));
714-
sink.setPattern(toPattern(polyline.getPatterns()));
714+
sink.setPattern(patternFromPigeon(polyline.getPatterns()));
715715
return polyline.getPolylineId();
716716
}
717717

@@ -850,32 +850,27 @@ private static List<List<LatLng>> toHoles(List<List<Messages.PlatformLatLng>> da
850850
return holes;
851851
}
852852

853-
private static List<PatternItem> toPattern(Object o) {
854-
final List<?> data = toList(o);
855-
856-
if (data.isEmpty()) {
853+
private static List<PatternItem> patternFromPigeon(
854+
List<Messages.PlatformPatternItem> patternItems) {
855+
if (patternItems.isEmpty()) {
857856
return null;
858857
}
859-
860-
final List<PatternItem> pattern = new ArrayList<>(data.size());
861-
862-
for (Object ob : data) {
863-
final List<?> patternItem = toList(ob);
864-
switch (toString(patternItem.get(0))) {
865-
case "dot":
858+
final List<PatternItem> pattern = new ArrayList<>();
859+
for (Messages.PlatformPatternItem patternItem : patternItems) {
860+
switch (patternItem.getType()) {
861+
case DOT:
866862
pattern.add(new Dot());
867863
break;
868-
case "dash":
869-
pattern.add(new Dash(toFloat(patternItem.get(1))));
864+
case DASH:
865+
assert patternItem.getLength() != null;
866+
pattern.add(new Dash(patternItem.getLength().floatValue()));
870867
break;
871-
case "gap":
872-
pattern.add(new Gap(toFloat(patternItem.get(1))));
868+
case GAP:
869+
assert patternItem.getLength() != null;
870+
pattern.add(new Gap(patternItem.getLength().floatValue()));
873871
break;
874-
default:
875-
throw new IllegalArgumentException("Cannot interpret " + pattern + " as PatternItem");
876872
}
877873
}
878-
879874
return pattern;
880875
}
881876

0 commit comments

Comments
 (0)