Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[google_maps_flutter_platform_interface] Convert BitmapDescriptor to typesafe subclasses #7699

Merged
merged 15 commits into from
Oct 4, 2024

Conversation

yaakovschectman
Copy link
Contributor

BitmapDescriptor is currently just a wrapper around JSON, with the exception of two of its subclasses. This converts all cases to typesafe structures without breaking the current API.

Part of flutter/flutter#155122

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@yaakovschectman yaakovschectman self-assigned this Sep 25, 2024
@yaakovschectman yaakovschectman marked this pull request as ready for review September 25, 2024 17:35
expect(identical(descriptorFromJson.toJson(), json), isTrue); // Same JSON
expect(descriptorFromJson.toJson(), json);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the bitmaps are no longer just wrapping JSON, toJson will not return the same reference as was passed to fromJson, though they will still be equal by comparison.

@@ -44,14 +51,14 @@ const double _naturalPixelRatio = 1.0;
/// a default marker icon.
/// Use the [BitmapDescriptor.defaultMarkerWithHue] to create a
/// [BitmapDescriptor] for a default marker icon with a hue value.
class BitmapDescriptor {
const BitmapDescriptor._(this._json);
abstract class BitmapDescriptor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was a breaking change but a spot check of the public usages in github show I am incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only ways to construct a BitmapDescriptor without constructing one of its subclasses was either through this private _ factory, which is removed here, or the below fromJson public factory, which this PR converts to a static method, so unless we are expecting public usages of this package to add new subclasses of BitmapDescriptor, I believe that neither making it abstract nor removing the _ factory should impact any public uses.


/// The inverse of .toJson.
// TODO(stuartmorgan): Remove this in the next breaking change.
@Deprecated('No longer supported')
BitmapDescriptor.fromJson(Object json) : _json = json {
assert(_json is List<dynamic>);
static BitmapDescriptor fromJson(Object json) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the : _json syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR removes the _json field from BitmapDescriptor, and since it also makes BitmapDescriptor an abstract class with a concrete subtype for each possible set of member data, fromJson needs to return an instance of one of those subtypes.

@@ -29,6 +29,13 @@ enum MapBitmapScaling {
none,
}

/// Convert a string from provided JSON to a MapBitmapScaling enum.
MapBitmapScaling mapBitmapScalingFromString(String mode) => switch (mode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be private so we're not increasing the API surface of the package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference would be visible for testing and keep the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be my thought as well, @stuartmorgan do you agree with this decision?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine; from a semver standpoint we consider those equivalent.

/// A BitmapDescriptor using the default marker.
class DefaultMarker extends BitmapDescriptor {
/// Provide an optional [hue] for the default marker.
const DefaultMarker([this.hue]) : super._();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use named parameters so that we can change the parameter set in the future without breaking changes (or being stuck with a growing positional list, which doesn't scale).

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG once the @visibleForTesting annotation is added.

@@ -5,6 +5,7 @@
import 'dart:async' show Future;
import 'dart:typed_data' show Uint8List;

import 'package:flutter/cupertino.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like your IDE chose a weird auto-import here; this should be a new show below instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Specifically, from foundation.dart)

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yaakovschectman yaakovschectman merged commit e28f004 into flutter:main Oct 4, 2024
76 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 7, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 7, 2024
flutter/packages@05bf1d4...bb00d34

2024-10-07 [email protected] [google_sign_in] Update Pigeon for non-nullable generics (flutter/packages#7785)
2024-10-07 [email protected] [path_provider] Update Android Pigeon for non-nullable generics  (flutter/packages#7783)
2024-10-07 [email protected] [rfw] Increase tolerance for material widget tests (flutter/packages#7148)
2024-10-05 [email protected] [various] Update Java compatibility version to 11 (flutter/packages#7795)
2024-10-04 [email protected] [video_player] Update Pigeon for non-nullable generics (flutter/packages#7790)
2024-10-04 [email protected] [go_router] Added missing implementation for the routerNeglect parameter in GoRouter (flutter/packages#7752)
2024-10-04 [email protected] [google_maps_flutter_platform_interface] Convert `BitmapDescriptor` to typesafe subclasses (flutter/packages#7699)
2024-10-04 [email protected] [google_maps_flutter_platform_interface] Convert `PatternItem` and `Cap` to typesafe structures. (flutter/packages#7703)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants