Skip to content

Commit

Permalink
[google_maps_flutter_android] Add PlatformCap pigeon type. (#7639)
Browse files Browse the repository at this point in the history
Replace old JSON implementation of polyline start/end cap with a
structured Pigeon.

flutter/flutter#154737

## 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`.)
- [x] 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
  • Loading branch information
yaakovschectman authored Oct 9, 2024
1 parent 345fa98 commit 44e7d73
Show file tree
Hide file tree
Showing 8 changed files with 445 additions and 172 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.14.9

* Adds `PlatformCap` for `PlatformPolyline.startCap` and `endCap`.

## 2.14.8

* Updates Java compatibility version to 11.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@ static String interpretPolylineOptions(
float density) {
sink.setConsumeTapEvents(polyline.getConsumesTapEvents());
sink.setColor(polyline.getColor().intValue());
sink.setEndCap(toCap(polyline.getEndCap(), assetManager, density));
sink.setStartCap(toCap(polyline.getStartCap(), assetManager, density));
sink.setEndCap(capFromPigeon(polyline.getEndCap(), assetManager, density));
sink.setStartCap(capFromPigeon(polyline.getStartCap(), assetManager, density));
sink.setGeodesic(polyline.getGeodesic());
sink.setJointType(jointTypeFromPigeon(polyline.getJointType()));
sink.setVisible(polyline.getVisible());
Expand Down Expand Up @@ -874,25 +874,24 @@ private static List<PatternItem> patternFromPigeon(
return pattern;
}

private static Cap toCap(Object o, AssetManager assetManager, float density) {
final List<?> data = toList(o);
switch (toString(data.get(0))) {
case "buttCap":
private static Cap capFromPigeon(
Messages.PlatformCap cap, AssetManager assetManager, float density) {
switch (cap.getType()) {
case BUTT_CAP:
return new ButtCap();
case "roundCap":
case ROUND_CAP:
return new RoundCap();
case "squareCap":
case SQUARE_CAP:
return new SquareCap();
case "customCap":
if (data.size() == 2) {
return new CustomCap(toBitmapDescriptor(data.get(1), assetManager, density));
} else {
return new CustomCap(
toBitmapDescriptor(data.get(1), assetManager, density), toFloat(data.get(2)));
case CUSTOM_CAP:
if (cap.getRefWidth() == null) {
throw new IllegalArgumentException("A Custom Cap must specify a refWidth value.");
}
default:
throw new IllegalArgumentException("Cannot interpret " + o + " as Cap");
return new CustomCap(
toBitmapDescriptor(cap.getBitmapDescriptor(), assetManager, density),
cap.getRefWidth().floatValue());
}
throw new IllegalArgumentException("Unrecognized Cap type: " + cap.getType());
}

static String interpretTileOverlayOptions(
Expand Down
Loading

0 comments on commit 44e7d73

Please sign in to comment.