From 24594a081676f2678fea4bb1e8d5d6253ee3f4c2 Mon Sep 17 00:00:00 2001 From: yaakovschectman <109111084+yaakovschectman@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:59:39 -0400 Subject: [PATCH] [google_maps_flutter_android] Convert `PlatformPolyline.pattern` to Pigeon (#7631) Creates a structured `PlatformPatternItem` pigeon class to use in `PlatformPolyline`. https://github.com/flutter/flutter/issues/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]. [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 --- .../google_maps_flutter_android/CHANGELOG.md | 4 + .../flutter/plugins/googlemaps/Convert.java | 33 +-- .../flutter/plugins/googlemaps/Messages.java | 257 +++++++++++++----- .../lib/src/google_maps_flutter_android.dart | 35 ++- .../lib/src/messages.g.dart | 169 +++++++----- .../pigeons/messages.dart | 20 +- .../google_maps_flutter_android/pubspec.yaml | 2 +- .../google_maps_flutter_android_test.dart | 6 +- 8 files changed, 366 insertions(+), 160 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md index 43817fca9e45..0dec52337777 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.14.7 + +* Adds `PlatformPatternItem` pigeon class to convert `PlatformPolyline.pattern`. + ## 2.14.6 * Converts 'PlatformCameraUpdate' to pigeon. diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java index fd86e0f3e3f4..6c7c103e4bdd 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java @@ -711,7 +711,7 @@ static String interpretPolylineOptions( sink.setWidth(polyline.getWidth()); sink.setZIndex(polyline.getZIndex()); sink.setPoints(pointsFromPigeon(polyline.getPoints())); - sink.setPattern(toPattern(polyline.getPatterns())); + sink.setPattern(patternFromPigeon(polyline.getPatterns())); return polyline.getPolylineId(); } @@ -850,32 +850,27 @@ private static List> toHoles(List> da return holes; } - private static List toPattern(Object o) { - final List data = toList(o); - - if (data.isEmpty()) { + private static List patternFromPigeon( + List patternItems) { + if (patternItems.isEmpty()) { return null; } - - final List pattern = new ArrayList<>(data.size()); - - for (Object ob : data) { - final List patternItem = toList(ob); - switch (toString(patternItem.get(0))) { - case "dot": + final List pattern = new ArrayList<>(); + for (Messages.PlatformPatternItem patternItem : patternItems) { + switch (patternItem.getType()) { + case DOT: pattern.add(new Dot()); break; - case "dash": - pattern.add(new Dash(toFloat(patternItem.get(1)))); + case DASH: + assert patternItem.getLength() != null; + pattern.add(new Dash(patternItem.getLength().floatValue())); break; - case "gap": - pattern.add(new Gap(toFloat(patternItem.get(1)))); + case GAP: + assert patternItem.getLength() != null; + pattern.add(new Gap(patternItem.getLength().floatValue())); break; - default: - throw new IllegalArgumentException("Cannot interpret " + pattern + " as PatternItem"); } } - return pattern; } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java index db1edfe11dc2..a258aea0cfce 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java @@ -113,6 +113,19 @@ public enum PlatformJointType { } } + /** Enumeration of possible types for PatternItem. */ + public enum PlatformPatternItemType { + DOT(0), + DASH(1), + GAP(2); + + final int index; + + PlatformPatternItemType(final int index) { + this.index = index; + } + } + /** * Pigeon representatation of a CameraPosition. * @@ -2440,18 +2453,14 @@ public void setJointType(@NonNull PlatformJointType setterArg) { this.jointType = setterArg; } - /** - * The pattern data, as JSON. Each element in this list should be set only from - * PatternItem.toJson, and the native code must interpret it according to the internal - * implementation details of that method. - */ - private @NonNull List patterns; + /** The pattern data, as a list of pattern items. */ + private @NonNull List patterns; - public @NonNull List getPatterns() { + public @NonNull List getPatterns() { return patterns; } - public void setPatterns(@NonNull List setterArg) { + public void setPatterns(@NonNull List setterArg) { if (setterArg == null) { throw new IllegalStateException("Nonnull field \"patterns\" is null."); } @@ -2625,10 +2634,10 @@ public static final class Builder { return this; } - private @Nullable List patterns; + private @Nullable List patterns; @CanIgnoreReturnValue - public @NonNull Builder setPatterns(@NonNull List setterArg) { + public @NonNull Builder setPatterns(@NonNull List setterArg) { this.patterns = setterArg; return this; } @@ -2730,7 +2739,7 @@ ArrayList toList() { Object jointType = pigeonVar_list.get(4); pigeonResult.setJointType((PlatformJointType) jointType); Object patterns = pigeonVar_list.get(5); - pigeonResult.setPatterns((List) patterns); + pigeonResult.setPatterns((List) patterns); Object points = pigeonVar_list.get(6); pigeonResult.setPoints((List) points); Object startCap = pigeonVar_list.get(7); @@ -2747,6 +2756,99 @@ ArrayList toList() { } } + /** + * Pigeon equivalent of the PatternItem class. + * + *

Generated class from Pigeon that represents data sent in messages. + */ + public static final class PlatformPatternItem { + private @NonNull PlatformPatternItemType type; + + public @NonNull PlatformPatternItemType getType() { + return type; + } + + public void setType(@NonNull PlatformPatternItemType setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"type\" is null."); + } + this.type = setterArg; + } + + private @Nullable Double length; + + public @Nullable Double getLength() { + return length; + } + + public void setLength(@Nullable Double setterArg) { + this.length = setterArg; + } + + /** Constructor is non-public to enforce null safety; use Builder. */ + PlatformPatternItem() {} + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformPatternItem that = (PlatformPatternItem) o; + return type.equals(that.type) && Objects.equals(length, that.length); + } + + @Override + public int hashCode() { + return Objects.hash(type, length); + } + + public static final class Builder { + + private @Nullable PlatformPatternItemType type; + + @CanIgnoreReturnValue + public @NonNull Builder setType(@NonNull PlatformPatternItemType setterArg) { + this.type = setterArg; + return this; + } + + private @Nullable Double length; + + @CanIgnoreReturnValue + public @NonNull Builder setLength(@Nullable Double setterArg) { + this.length = setterArg; + return this; + } + + public @NonNull PlatformPatternItem build() { + PlatformPatternItem pigeonReturn = new PlatformPatternItem(); + pigeonReturn.setType(type); + pigeonReturn.setLength(length); + return pigeonReturn; + } + } + + @NonNull + ArrayList toList() { + ArrayList toListResult = new ArrayList<>(2); + toListResult.add(type); + toListResult.add(length); + return toListResult; + } + + static @NonNull PlatformPatternItem fromList(@NonNull ArrayList pigeonVar_list) { + PlatformPatternItem pigeonResult = new PlatformPatternItem(); + Object type = pigeonVar_list.get(0); + pigeonResult.setType((PlatformPatternItemType) type); + Object length = pigeonVar_list.get(1); + pigeonResult.setLength((Double) length); + return pigeonResult; + } + } + /** * Pigeon equivalent of the Tile class. * @@ -4797,66 +4899,75 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { return value == null ? null : PlatformJointType.values()[((Long) value).intValue()]; } case (byte) 132: - return PlatformCameraPosition.fromList((ArrayList) readValue(buffer)); + { + Object value = readValue(buffer); + return value == null + ? null + : PlatformPatternItemType.values()[((Long) value).intValue()]; + } case (byte) 133: - return PlatformCameraUpdate.fromList((ArrayList) readValue(buffer)); + return PlatformCameraPosition.fromList((ArrayList) readValue(buffer)); case (byte) 134: + return PlatformCameraUpdate.fromList((ArrayList) readValue(buffer)); + case (byte) 135: return PlatformCameraUpdateNewCameraPosition.fromList( (ArrayList) readValue(buffer)); - case (byte) 135: - return PlatformCameraUpdateNewLatLng.fromList((ArrayList) readValue(buffer)); case (byte) 136: + return PlatformCameraUpdateNewLatLng.fromList((ArrayList) readValue(buffer)); + case (byte) 137: return PlatformCameraUpdateNewLatLngBounds.fromList( (ArrayList) readValue(buffer)); - case (byte) 137: - return PlatformCameraUpdateNewLatLngZoom.fromList((ArrayList) readValue(buffer)); case (byte) 138: - return PlatformCameraUpdateScrollBy.fromList((ArrayList) readValue(buffer)); + return PlatformCameraUpdateNewLatLngZoom.fromList((ArrayList) readValue(buffer)); case (byte) 139: - return PlatformCameraUpdateZoomBy.fromList((ArrayList) readValue(buffer)); + return PlatformCameraUpdateScrollBy.fromList((ArrayList) readValue(buffer)); case (byte) 140: - return PlatformCameraUpdateZoom.fromList((ArrayList) readValue(buffer)); + return PlatformCameraUpdateZoomBy.fromList((ArrayList) readValue(buffer)); case (byte) 141: - return PlatformCameraUpdateZoomTo.fromList((ArrayList) readValue(buffer)); + return PlatformCameraUpdateZoom.fromList((ArrayList) readValue(buffer)); case (byte) 142: - return PlatformCircle.fromList((ArrayList) readValue(buffer)); + return PlatformCameraUpdateZoomTo.fromList((ArrayList) readValue(buffer)); case (byte) 143: - return PlatformHeatmap.fromList((ArrayList) readValue(buffer)); + return PlatformCircle.fromList((ArrayList) readValue(buffer)); case (byte) 144: - return PlatformClusterManager.fromList((ArrayList) readValue(buffer)); + return PlatformHeatmap.fromList((ArrayList) readValue(buffer)); case (byte) 145: - return PlatformOffset.fromList((ArrayList) readValue(buffer)); + return PlatformClusterManager.fromList((ArrayList) readValue(buffer)); case (byte) 146: - return PlatformInfoWindow.fromList((ArrayList) readValue(buffer)); + return PlatformOffset.fromList((ArrayList) readValue(buffer)); case (byte) 147: - return PlatformMarker.fromList((ArrayList) readValue(buffer)); + return PlatformInfoWindow.fromList((ArrayList) readValue(buffer)); case (byte) 148: - return PlatformPolygon.fromList((ArrayList) readValue(buffer)); + return PlatformMarker.fromList((ArrayList) readValue(buffer)); case (byte) 149: - return PlatformPolyline.fromList((ArrayList) readValue(buffer)); + return PlatformPolygon.fromList((ArrayList) readValue(buffer)); case (byte) 150: - return PlatformTile.fromList((ArrayList) readValue(buffer)); + return PlatformPolyline.fromList((ArrayList) readValue(buffer)); case (byte) 151: - return PlatformTileOverlay.fromList((ArrayList) readValue(buffer)); + return PlatformPatternItem.fromList((ArrayList) readValue(buffer)); case (byte) 152: - return PlatformEdgeInsets.fromList((ArrayList) readValue(buffer)); + return PlatformTile.fromList((ArrayList) readValue(buffer)); case (byte) 153: - return PlatformLatLng.fromList((ArrayList) readValue(buffer)); + return PlatformTileOverlay.fromList((ArrayList) readValue(buffer)); case (byte) 154: - return PlatformLatLngBounds.fromList((ArrayList) readValue(buffer)); + return PlatformEdgeInsets.fromList((ArrayList) readValue(buffer)); case (byte) 155: - return PlatformCluster.fromList((ArrayList) readValue(buffer)); + return PlatformLatLng.fromList((ArrayList) readValue(buffer)); case (byte) 156: - return PlatformCameraTargetBounds.fromList((ArrayList) readValue(buffer)); + return PlatformLatLngBounds.fromList((ArrayList) readValue(buffer)); case (byte) 157: - return PlatformMapViewCreationParams.fromList((ArrayList) readValue(buffer)); + return PlatformCluster.fromList((ArrayList) readValue(buffer)); case (byte) 158: - return PlatformMapConfiguration.fromList((ArrayList) readValue(buffer)); + return PlatformCameraTargetBounds.fromList((ArrayList) readValue(buffer)); case (byte) 159: - return PlatformPoint.fromList((ArrayList) readValue(buffer)); + return PlatformMapViewCreationParams.fromList((ArrayList) readValue(buffer)); case (byte) 160: - return PlatformTileLayer.fromList((ArrayList) readValue(buffer)); + return PlatformMapConfiguration.fromList((ArrayList) readValue(buffer)); case (byte) 161: + return PlatformPoint.fromList((ArrayList) readValue(buffer)); + case (byte) 162: + return PlatformTileLayer.fromList((ArrayList) readValue(buffer)); + case (byte) 163: return PlatformZoomRange.fromList((ArrayList) readValue(buffer)); default: return super.readValueOfType(type, buffer); @@ -4874,95 +4985,101 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { } else if (value instanceof PlatformJointType) { stream.write(131); writeValue(stream, value == null ? null : ((PlatformJointType) value).index); - } else if (value instanceof PlatformCameraPosition) { + } else if (value instanceof PlatformPatternItemType) { stream.write(132); + writeValue(stream, value == null ? null : ((PlatformPatternItemType) value).index); + } else if (value instanceof PlatformCameraPosition) { + stream.write(133); writeValue(stream, ((PlatformCameraPosition) value).toList()); } else if (value instanceof PlatformCameraUpdate) { - stream.write(133); + stream.write(134); writeValue(stream, ((PlatformCameraUpdate) value).toList()); } else if (value instanceof PlatformCameraUpdateNewCameraPosition) { - stream.write(134); + stream.write(135); writeValue(stream, ((PlatformCameraUpdateNewCameraPosition) value).toList()); } else if (value instanceof PlatformCameraUpdateNewLatLng) { - stream.write(135); + stream.write(136); writeValue(stream, ((PlatformCameraUpdateNewLatLng) value).toList()); } else if (value instanceof PlatformCameraUpdateNewLatLngBounds) { - stream.write(136); + stream.write(137); writeValue(stream, ((PlatformCameraUpdateNewLatLngBounds) value).toList()); } else if (value instanceof PlatformCameraUpdateNewLatLngZoom) { - stream.write(137); + stream.write(138); writeValue(stream, ((PlatformCameraUpdateNewLatLngZoom) value).toList()); } else if (value instanceof PlatformCameraUpdateScrollBy) { - stream.write(138); + stream.write(139); writeValue(stream, ((PlatformCameraUpdateScrollBy) value).toList()); } else if (value instanceof PlatformCameraUpdateZoomBy) { - stream.write(139); + stream.write(140); writeValue(stream, ((PlatformCameraUpdateZoomBy) value).toList()); } else if (value instanceof PlatformCameraUpdateZoom) { - stream.write(140); + stream.write(141); writeValue(stream, ((PlatformCameraUpdateZoom) value).toList()); } else if (value instanceof PlatformCameraUpdateZoomTo) { - stream.write(141); + stream.write(142); writeValue(stream, ((PlatformCameraUpdateZoomTo) value).toList()); } else if (value instanceof PlatformCircle) { - stream.write(142); + stream.write(143); writeValue(stream, ((PlatformCircle) value).toList()); } else if (value instanceof PlatformHeatmap) { - stream.write(143); + stream.write(144); writeValue(stream, ((PlatformHeatmap) value).toList()); } else if (value instanceof PlatformClusterManager) { - stream.write(144); + stream.write(145); writeValue(stream, ((PlatformClusterManager) value).toList()); } else if (value instanceof PlatformOffset) { - stream.write(145); + stream.write(146); writeValue(stream, ((PlatformOffset) value).toList()); } else if (value instanceof PlatformInfoWindow) { - stream.write(146); + stream.write(147); writeValue(stream, ((PlatformInfoWindow) value).toList()); } else if (value instanceof PlatformMarker) { - stream.write(147); + stream.write(148); writeValue(stream, ((PlatformMarker) value).toList()); } else if (value instanceof PlatformPolygon) { - stream.write(148); + stream.write(149); writeValue(stream, ((PlatformPolygon) value).toList()); } else if (value instanceof PlatformPolyline) { - stream.write(149); + stream.write(150); writeValue(stream, ((PlatformPolyline) value).toList()); + } else if (value instanceof PlatformPatternItem) { + stream.write(151); + writeValue(stream, ((PlatformPatternItem) value).toList()); } else if (value instanceof PlatformTile) { - stream.write(150); + stream.write(152); writeValue(stream, ((PlatformTile) value).toList()); } else if (value instanceof PlatformTileOverlay) { - stream.write(151); + stream.write(153); writeValue(stream, ((PlatformTileOverlay) value).toList()); } else if (value instanceof PlatformEdgeInsets) { - stream.write(152); + stream.write(154); writeValue(stream, ((PlatformEdgeInsets) value).toList()); } else if (value instanceof PlatformLatLng) { - stream.write(153); + stream.write(155); writeValue(stream, ((PlatformLatLng) value).toList()); } else if (value instanceof PlatformLatLngBounds) { - stream.write(154); + stream.write(156); writeValue(stream, ((PlatformLatLngBounds) value).toList()); } else if (value instanceof PlatformCluster) { - stream.write(155); + stream.write(157); writeValue(stream, ((PlatformCluster) value).toList()); } else if (value instanceof PlatformCameraTargetBounds) { - stream.write(156); + stream.write(158); writeValue(stream, ((PlatformCameraTargetBounds) value).toList()); } else if (value instanceof PlatformMapViewCreationParams) { - stream.write(157); + stream.write(159); writeValue(stream, ((PlatformMapViewCreationParams) value).toList()); } else if (value instanceof PlatformMapConfiguration) { - stream.write(158); + stream.write(160); writeValue(stream, ((PlatformMapConfiguration) value).toList()); } else if (value instanceof PlatformPoint) { - stream.write(159); + stream.write(161); writeValue(stream, ((PlatformPoint) value).toList()); } else if (value instanceof PlatformTileLayer) { - stream.write(160); + stream.write(162); writeValue(stream, ((PlatformTileLayer) value).toList()); } else if (value instanceof PlatformZoomRange) { - stream.write(161); + stream.write(163); writeValue(stream, ((PlatformZoomRange) value).toList()); } else { super.writeValue(stream, value); diff --git a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart index 76d39e816a33..10fb6ece7558 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart @@ -769,9 +769,8 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform { static PlatformPolyline _platformPolylineFromPolyline(Polyline polyline) { final List points = polyline.points.map(_platformLatLngFromLatLng).toList(); - final List pattern = polyline.patterns.map((PatternItem item) { - return item.toJson(); - }).toList(); + final List pattern = + polyline.patterns.map(platformPatternItemFromPatternItem).toList(); return PlatformPolyline( polylineId: polyline.polylineId.value, consumesTapEvents: polyline.consumeTapEvents, @@ -1220,6 +1219,36 @@ PlatformJointType platformJointTypeFromJointType(JointType jointType) { return PlatformJointType.mitered; } +/// Converts a PatternItem to Pigeon's PlatformPatternItem for PlatformPolyline +/// pattern member. +@visibleForTesting +PlatformPatternItem platformPatternItemFromPatternItem(PatternItem item) { + final List json = item.toJson() as List; + final String tag = json[0] as String; + PlatformPatternItemType type; + double? length; + + /// These string values identify the type of pattern. They are defined and + /// used in the PatternItem class's factory methods in + /// lib/src/types/pattern_item.dart, in the + /// google_maps_flutter_platform_interface package. + // TODO(schectman): Convert PatternItem to structured data. + // https://github.com/flutter/flutter/issues/155121 + switch (tag) { + case 'dot': + type = PlatformPatternItemType.dot; + case 'dash': + type = PlatformPatternItemType.dash; + length = json[1] as double; + case 'gap': + type = PlatformPatternItemType.gap; + length = json[1] as double; + default: + throw ArgumentError('Invalid tag "$tag for PatternItem type.', 'item'); + } + return PlatformPatternItem(type: type, length: length); +} + /// Update specification for a set of [TileOverlay]s. // TODO(stuartmorgan): Fix the missing export of this class in the platform // interface, and remove this copy. diff --git a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart index 62655d2dac83..958e0bfdc996 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart @@ -50,6 +50,13 @@ enum PlatformJointType { round, } +/// Enumeration of possible types for PatternItem. +enum PlatformPatternItemType { + dot, + dash, + gap, +} + /// Pigeon representatation of a CameraPosition. class PlatformCameraPosition { PlatformCameraPosition({ @@ -657,8 +664,8 @@ class PlatformPolyline { /// The joint type. PlatformJointType jointType; - /// The pattern data, as JSON. Each element in this list should be set only from PatternItem.toJson, and the native code must interpret it according to the internal implementation details of that method. - List patterns; + /// The pattern data, as a list of pattern items. + List patterns; List points; @@ -698,7 +705,7 @@ class PlatformPolyline { color: result[2]! as int, geodesic: result[3]! as bool, jointType: result[4]! as PlatformJointType, - patterns: (result[5] as List?)!.cast(), + patterns: (result[5] as List?)!.cast(), points: (result[6] as List?)!.cast(), startCap: result[7]!, endCap: result[8]!, @@ -709,6 +716,33 @@ class PlatformPolyline { } } +/// Pigeon equivalent of the PatternItem class. +class PlatformPatternItem { + PlatformPatternItem({ + required this.type, + this.length, + }); + + PlatformPatternItemType type; + + double? length; + + Object encode() { + return [ + type, + length, + ]; + } + + static PlatformPatternItem decode(Object result) { + result as List; + return PlatformPatternItem( + type: result[0]! as PlatformPatternItemType, + length: result[1] as double?, + ); + } +} + /// Pigeon equivalent of the Tile class. class PlatformTile { PlatformTile({ @@ -1230,95 +1264,101 @@ class _PigeonCodec extends StandardMessageCodec { } else if (value is PlatformJointType) { buffer.putUint8(131); writeValue(buffer, value.index); - } else if (value is PlatformCameraPosition) { + } else if (value is PlatformPatternItemType) { buffer.putUint8(132); + writeValue(buffer, value.index); + } else if (value is PlatformCameraPosition) { + buffer.putUint8(133); writeValue(buffer, value.encode()); } else if (value is PlatformCameraUpdate) { - buffer.putUint8(133); + buffer.putUint8(134); writeValue(buffer, value.encode()); } else if (value is PlatformCameraUpdateNewCameraPosition) { - buffer.putUint8(134); + buffer.putUint8(135); writeValue(buffer, value.encode()); } else if (value is PlatformCameraUpdateNewLatLng) { - buffer.putUint8(135); + buffer.putUint8(136); writeValue(buffer, value.encode()); } else if (value is PlatformCameraUpdateNewLatLngBounds) { - buffer.putUint8(136); + buffer.putUint8(137); writeValue(buffer, value.encode()); } else if (value is PlatformCameraUpdateNewLatLngZoom) { - buffer.putUint8(137); + buffer.putUint8(138); writeValue(buffer, value.encode()); } else if (value is PlatformCameraUpdateScrollBy) { - buffer.putUint8(138); + buffer.putUint8(139); writeValue(buffer, value.encode()); } else if (value is PlatformCameraUpdateZoomBy) { - buffer.putUint8(139); + buffer.putUint8(140); writeValue(buffer, value.encode()); } else if (value is PlatformCameraUpdateZoom) { - buffer.putUint8(140); + buffer.putUint8(141); writeValue(buffer, value.encode()); } else if (value is PlatformCameraUpdateZoomTo) { - buffer.putUint8(141); + buffer.putUint8(142); writeValue(buffer, value.encode()); } else if (value is PlatformCircle) { - buffer.putUint8(142); + buffer.putUint8(143); writeValue(buffer, value.encode()); } else if (value is PlatformHeatmap) { - buffer.putUint8(143); + buffer.putUint8(144); writeValue(buffer, value.encode()); } else if (value is PlatformClusterManager) { - buffer.putUint8(144); + buffer.putUint8(145); writeValue(buffer, value.encode()); } else if (value is PlatformOffset) { - buffer.putUint8(145); + buffer.putUint8(146); writeValue(buffer, value.encode()); } else if (value is PlatformInfoWindow) { - buffer.putUint8(146); + buffer.putUint8(147); writeValue(buffer, value.encode()); } else if (value is PlatformMarker) { - buffer.putUint8(147); + buffer.putUint8(148); writeValue(buffer, value.encode()); } else if (value is PlatformPolygon) { - buffer.putUint8(148); + buffer.putUint8(149); writeValue(buffer, value.encode()); } else if (value is PlatformPolyline) { - buffer.putUint8(149); + buffer.putUint8(150); + writeValue(buffer, value.encode()); + } else if (value is PlatformPatternItem) { + buffer.putUint8(151); writeValue(buffer, value.encode()); } else if (value is PlatformTile) { - buffer.putUint8(150); + buffer.putUint8(152); writeValue(buffer, value.encode()); } else if (value is PlatformTileOverlay) { - buffer.putUint8(151); + buffer.putUint8(153); writeValue(buffer, value.encode()); } else if (value is PlatformEdgeInsets) { - buffer.putUint8(152); + buffer.putUint8(154); writeValue(buffer, value.encode()); } else if (value is PlatformLatLng) { - buffer.putUint8(153); + buffer.putUint8(155); writeValue(buffer, value.encode()); } else if (value is PlatformLatLngBounds) { - buffer.putUint8(154); + buffer.putUint8(156); writeValue(buffer, value.encode()); } else if (value is PlatformCluster) { - buffer.putUint8(155); + buffer.putUint8(157); writeValue(buffer, value.encode()); } else if (value is PlatformCameraTargetBounds) { - buffer.putUint8(156); + buffer.putUint8(158); writeValue(buffer, value.encode()); } else if (value is PlatformMapViewCreationParams) { - buffer.putUint8(157); + buffer.putUint8(159); writeValue(buffer, value.encode()); } else if (value is PlatformMapConfiguration) { - buffer.putUint8(158); + buffer.putUint8(160); writeValue(buffer, value.encode()); } else if (value is PlatformPoint) { - buffer.putUint8(159); + buffer.putUint8(161); writeValue(buffer, value.encode()); } else if (value is PlatformTileLayer) { - buffer.putUint8(160); + buffer.putUint8(162); writeValue(buffer, value.encode()); } else if (value is PlatformZoomRange) { - buffer.putUint8(161); + buffer.putUint8(163); writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); @@ -1338,64 +1378,69 @@ class _PigeonCodec extends StandardMessageCodec { final int? value = readValue(buffer) as int?; return value == null ? null : PlatformJointType.values[value]; case 132: - return PlatformCameraPosition.decode(readValue(buffer)!); + final int? value = readValue(buffer) as int?; + return value == null ? null : PlatformPatternItemType.values[value]; case 133: - return PlatformCameraUpdate.decode(readValue(buffer)!); + return PlatformCameraPosition.decode(readValue(buffer)!); case 134: - return PlatformCameraUpdateNewCameraPosition.decode(readValue(buffer)!); + return PlatformCameraUpdate.decode(readValue(buffer)!); case 135: - return PlatformCameraUpdateNewLatLng.decode(readValue(buffer)!); + return PlatformCameraUpdateNewCameraPosition.decode(readValue(buffer)!); case 136: - return PlatformCameraUpdateNewLatLngBounds.decode(readValue(buffer)!); + return PlatformCameraUpdateNewLatLng.decode(readValue(buffer)!); case 137: - return PlatformCameraUpdateNewLatLngZoom.decode(readValue(buffer)!); + return PlatformCameraUpdateNewLatLngBounds.decode(readValue(buffer)!); case 138: - return PlatformCameraUpdateScrollBy.decode(readValue(buffer)!); + return PlatformCameraUpdateNewLatLngZoom.decode(readValue(buffer)!); case 139: - return PlatformCameraUpdateZoomBy.decode(readValue(buffer)!); + return PlatformCameraUpdateScrollBy.decode(readValue(buffer)!); case 140: - return PlatformCameraUpdateZoom.decode(readValue(buffer)!); + return PlatformCameraUpdateZoomBy.decode(readValue(buffer)!); case 141: - return PlatformCameraUpdateZoomTo.decode(readValue(buffer)!); + return PlatformCameraUpdateZoom.decode(readValue(buffer)!); case 142: - return PlatformCircle.decode(readValue(buffer)!); + return PlatformCameraUpdateZoomTo.decode(readValue(buffer)!); case 143: - return PlatformHeatmap.decode(readValue(buffer)!); + return PlatformCircle.decode(readValue(buffer)!); case 144: - return PlatformClusterManager.decode(readValue(buffer)!); + return PlatformHeatmap.decode(readValue(buffer)!); case 145: - return PlatformOffset.decode(readValue(buffer)!); + return PlatformClusterManager.decode(readValue(buffer)!); case 146: - return PlatformInfoWindow.decode(readValue(buffer)!); + return PlatformOffset.decode(readValue(buffer)!); case 147: - return PlatformMarker.decode(readValue(buffer)!); + return PlatformInfoWindow.decode(readValue(buffer)!); case 148: - return PlatformPolygon.decode(readValue(buffer)!); + return PlatformMarker.decode(readValue(buffer)!); case 149: - return PlatformPolyline.decode(readValue(buffer)!); + return PlatformPolygon.decode(readValue(buffer)!); case 150: - return PlatformTile.decode(readValue(buffer)!); + return PlatformPolyline.decode(readValue(buffer)!); case 151: - return PlatformTileOverlay.decode(readValue(buffer)!); + return PlatformPatternItem.decode(readValue(buffer)!); case 152: - return PlatformEdgeInsets.decode(readValue(buffer)!); + return PlatformTile.decode(readValue(buffer)!); case 153: - return PlatformLatLng.decode(readValue(buffer)!); + return PlatformTileOverlay.decode(readValue(buffer)!); case 154: - return PlatformLatLngBounds.decode(readValue(buffer)!); + return PlatformEdgeInsets.decode(readValue(buffer)!); case 155: - return PlatformCluster.decode(readValue(buffer)!); + return PlatformLatLng.decode(readValue(buffer)!); case 156: - return PlatformCameraTargetBounds.decode(readValue(buffer)!); + return PlatformLatLngBounds.decode(readValue(buffer)!); case 157: - return PlatformMapViewCreationParams.decode(readValue(buffer)!); + return PlatformCluster.decode(readValue(buffer)!); case 158: - return PlatformMapConfiguration.decode(readValue(buffer)!); + return PlatformCameraTargetBounds.decode(readValue(buffer)!); case 159: - return PlatformPoint.decode(readValue(buffer)!); + return PlatformMapViewCreationParams.decode(readValue(buffer)!); case 160: - return PlatformTileLayer.decode(readValue(buffer)!); + return PlatformMapConfiguration.decode(readValue(buffer)!); case 161: + return PlatformPoint.decode(readValue(buffer)!); + case 162: + return PlatformTileLayer.decode(readValue(buffer)!); + case 163: return PlatformZoomRange.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); diff --git a/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart b/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart index 002b3c0a60e8..8ed6ebb061e1 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart @@ -263,9 +263,8 @@ class PlatformPolyline { /// The joint type. final PlatformJointType jointType; - /// The pattern data, as JSON. Each element in this list should be set only from PatternItem.toJson, and the native code must interpret it according to the internal implementation details of that method. - // TODO(schectman): Convert field to structured data. - final List patterns; + /// The pattern data, as a list of pattern items. + final List patterns; final List points; /// The start and end cap data, as JSON. These should be set only from Cap.toJson, and the native code must interpret it according to the internal implementation details of that method. @@ -277,6 +276,21 @@ class PlatformPolyline { final int zIndex; } +/// Enumeration of possible types for PatternItem. +enum PlatformPatternItemType { + dot, + dash, + gap, +} + +/// Pigeon equivalent of the PatternItem class. +class PlatformPatternItem { + PlatformPatternItem({required this.type, this.length}); + + final PlatformPatternItemType type; + final double? length; +} + /// Pigeon equivalent of the Tile class. class PlatformTile { PlatformTile({required this.width, required this.height, required this.data}); diff --git a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml index 657c6c05f132..fd17ae6e0535 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_android description: Android implementation of the google_maps_flutter plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 2.14.6 +version: 2.14.7 environment: sdk: ^3.4.0 diff --git a/packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart b/packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart index 9219d1205d6e..bd2ceb82dabe 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart @@ -567,8 +567,10 @@ void main() { expect(point?.longitude, actual.points[i]?.longitude); } expect(actual.patterns.length, expected.patterns.length); - for (final (int i, Object? pattern) in actual.patterns.indexed) { - expect(pattern, expected.patterns[i].toJson()); + for (final (int i, PlatformPatternItem? pattern) + in actual.patterns.indexed) { + expect(pattern?.encode(), + platformPatternItemFromPatternItem(expected.patterns[i]).encode()); } }