-
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] Add style
to widget
#6192
Changes from 13 commits
15539cc
fc93d0b
fedcb40
1dddbb0
2434a00
e0355df
be284f3
22837ba
7721166
d4c9bfb
dd188d1
2e8a190
36a6f84
1de84db
ffbfa0a
953fb8e
4a8acf3
f74ea3b
db1c58e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ class GoogleMap extends StatefulWidget { | |
const GoogleMap({ | ||
super.key, | ||
required this.initialCameraPosition, | ||
this.style, | ||
this.onMapCreated, | ||
this.gestureRecognizers = const <Factory<OneSequenceGestureRecognizer>>{}, | ||
this.webGestureHandling, | ||
|
@@ -136,6 +137,19 @@ class GoogleMap extends StatefulWidget { | |
/// The initial position of the map's camera. | ||
final CameraPosition initialCameraPosition; | ||
|
||
/// The style for the map. | ||
/// | ||
/// Set to null to clear any previous custom styling. | ||
/// | ||
/// If problems were detected with the [mapStyle], including un-parsable | ||
/// styling JSON, unrecognized feature type, unrecognized element type, or | ||
/// invalid styler keys, the style is left unchanged, and the error can be | ||
/// retrieved with [GoogleMapController.getStyleError]. | ||
/// | ||
/// The style string can be generated using the | ||
/// [map style tool](https://mapstyle.withgoogle.com/). | ||
final String? style; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way at all to make this a type safe object? If not can we at least point users to https://developers.google.com/maps/documentation/cloud-customization which does not require app updates and a stringly typed api. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not in any useful way. The native objects are opaque objects created from a string that is supposed to be a JSON string. So the options are:
If you follow the link there in this comment for generating the JSON style, you'll see that we don't really need to do that at the plugin level, as the SDK's docs and tool are very aggressive about this. (Also, there are significant caveats, like cloud style requires a per-load charge, and doesn't work on all Android devices, which is more than I want to get into in the comments here. I'd rather err on the side of being a neutral wrapper of the SDKs, and let the SDK docs steer people.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can definitely be made a type-safe object (we have a "type-safe-ish version" in the web version); the value of the String version of this property is that it can be generated/tweaked (and then copy-pasted) from here: https://mapstyle.withgoogle.com (and probably others) HOWEVER, one thing that Google Maps SDK seems to be doing is to call this feature "legacy styling", so maybe this property could be called: There's even documentation on how to migrate from this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, technically there is a third option: we could—in our wrapper that is already under-resourced—reverse-engineer a complex object graph from docs, thus building and maintaining a much more complex API than what the SDKs provide, creating a ton of work for us, only to throw away all that structure and re-encode it as a string anyway at the SDK boundary. And thereby make the existing tools for these styles harder for our clients to use. And also being inconsistent with our It's theoretically possible, but I don't see any actual upsides.
Their high-level docs call it legacy style. The actual SDKs, and the code-level API docs for those SDKs, do not use that language anywhere that I have seen. I do not want to be in the business of being significantly more opinionated in the code about what APIs people should or should not use than the people actually maintaining the SDK we are wrapping. I also don't want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM, |
||
|
||
/// True if the map should show a compass when rotated. | ||
final bool compassEnabled; | ||
|
||
|
@@ -556,5 +570,8 @@ MapConfiguration _configurationFromMapWidget(GoogleMap map) { | |
trafficEnabled: map.trafficEnabled, | ||
buildingsEnabled: map.buildingsEnabled, | ||
cloudMapId: map.cloudMapId, | ||
// A null style in the widget means no style, which is expressed as '' in | ||
// the configuration to distinguish from no change (null). | ||
style: map.style ?? '', | ||
); | ||
} |
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.
Should this say that it will get errors for the current mapid only?
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.
MapController is a per-map object; it's created with this ID.