-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
expect(identical(descriptorFromJson.toJson(), json), isTrue); // Same JSON | ||
expect(descriptorFromJson.toJson(), json); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you prefer we mark it @visibleForTesting
, or remove the test https://github.com/flutter/packages/pull/7699/files#diff-a8066076d538f1e1e21b27bac466302cb9317b643500ce81b991102a94611070R685?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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._(); |
There was a problem hiding this comment.
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).
There was a problem hiding this 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.
1ff2c26
to
cdcae66
Compare
@@ -5,6 +5,7 @@ | |||
import 'dart:async' show Future; | |||
import 'dart:typed_data' show Uint8List; | |||
|
|||
import 'package:flutter/cupertino.dart'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Specifically, from foundation.dart
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…criptor` to typesafe subclasses (flutter/packages#7699)
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
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
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.