Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
LatLng,
LatLngBounds,
MapBitmapScaling,
MapColorScheme,
MapStyleException,
MapType,
Marker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class GoogleMap extends StatefulWidget {
this.onTap,
this.onLongPress,
this.cloudMapId,
this.colorScheme,
});

/// Callback method for when the map is ready to be used.
Expand Down Expand Up @@ -373,6 +374,9 @@ class GoogleMap extends StatefulWidget {
/// for more details.
final String? cloudMapId;

/// Color scheme for the map
final MapColorScheme? colorScheme;

/// Creates a [State] for this [GoogleMap].
@override
State createState() => _GoogleMapState();
Expand Down Expand Up @@ -724,6 +728,7 @@ MapConfiguration _configurationFromMapWidget(GoogleMap map) {
trafficEnabled: map.trafficEnabled,
buildingsEnabled: map.buildingsEnabled,
cloudMapId: map.cloudMapId,
colorScheme: map.colorScheme,
// 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 ?? '',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// The color scheme of the map to be used with cloud styles
enum MapColorScheme { light, dark, followSystem }
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MapConfiguration {
String? cloudMapId,
this.style,
this.markerType,
this.colorScheme,
}) : mapId = mapId ?? cloudMapId;

/// This setting controls how the API handles gestures on the map. Web only.
Expand Down Expand Up @@ -152,6 +153,9 @@ class MapConfiguration {
@Deprecated('cloudMapId is deprecated. Use mapId instead.')
String? get cloudMapId => mapId;

/// Preferred color scheme for the map in web platform
final MapColorScheme? colorScheme;

/// Returns a new options object containing only the values of this instance
/// that are different from [other].
MapConfiguration diffFrom(MapConfiguration other) {
Expand Down Expand Up @@ -225,6 +229,7 @@ class MapConfiguration {
? buildingsEnabled
: null,
mapId: mapId != other.mapId ? mapId : null,
colorScheme: colorScheme != other.colorScheme ? colorScheme : null,
style: style != other.style ? style : null,
markerType: markerType != other.markerType ? markerType : null,
);
Expand Down Expand Up @@ -264,6 +269,7 @@ class MapConfiguration {
buildingsEnabled: diff.buildingsEnabled ?? buildingsEnabled,
mapId: diff.mapId ?? mapId,
style: diff.style ?? style,
colorScheme: diff.colorScheme ?? colorScheme,
markerType: diff.markerType ?? markerType,
);
}
Expand Down Expand Up @@ -293,6 +299,7 @@ class MapConfiguration {
trafficEnabled == null &&
buildingsEnabled == null &&
mapId == null &&
colorScheme == null &&
style == null &&
markerType == null;

Expand Down Expand Up @@ -329,6 +336,7 @@ class MapConfiguration {
buildingsEnabled == other.buildingsEnabled &&
mapId == other.mapId &&
style == other.style &&
colorScheme == other.colorScheme &&
markerType == other.markerType;
}

Expand Down Expand Up @@ -358,6 +366,7 @@ class MapConfiguration {
buildingsEnabled,
mapId,
style,
colorScheme,
markerType,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export 'heatmap.dart';
export 'heatmap_updates.dart';
export 'joint_type.dart';
export 'location.dart';
export 'map_color_scheme.dart';
export 'map_configuration.dart';
export 'map_objects.dart';
export 'map_widget_configuration.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 0.5.14+4

* Updates minimum supported SDK version to Flutter 3.32/Dart 3.8.
* Adds `colorScheme` support for cloud-based maps styling brightness.

## 0.5.14+3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,35 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions(

options.mapId = configuration.mapId;

// Convert the color scheme, if any, and set it
final gmaps.ColorScheme? jsColorScheme = _gmapTypeColorSchemeForPluginColor(
configuration.colorScheme,
);
if (jsColorScheme != null) {
options.colorScheme = jsColorScheme;
}

return options;
}

/// Converts a [MapColorScheme] into a [gmaps.ColorScheme]
gmaps.ColorScheme? _gmapTypeColorSchemeForPluginColor(MapColorScheme? scheme) {
// Guard clause for null
if (scheme == null) {
return null;
}

// Map to gmaps.ColorScheme
switch (scheme) {
case MapColorScheme.dark:
return gmaps.ColorScheme.DARK;
case MapColorScheme.light:
return gmaps.ColorScheme.LIGHT;
case MapColorScheme.followSystem:
return gmaps.ColorScheme.FOLLOW_SYSTEM;
}
}
Comment on lines +146 to +161

Choose a reason for hiding this comment

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

medium

This function can be made more concise by using a switch expression, which is available in this version of Dart. This improves readability by reducing boilerplate.

gmaps.ColorScheme? _gmapTypeColorSchemeForPluginColor(MapColorScheme? scheme) {
  return switch (scheme) {
    MapColorScheme.dark => gmaps.ColorScheme.DARK,
    MapColorScheme.light => gmaps.ColorScheme.LIGHT,
    MapColorScheme.followSystem => gmaps.ColorScheme.FOLLOW_SYSTEM,
    null => null,
  };
}

Copy link
Author

Choose a reason for hiding this comment

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

I had considered this, but decided to match the style of the below _gmapTypeIDForPluginType function, which uses the older more verbose switch syntax.


gmaps.MapTypeId _gmapTypeIDForPluginType(MapType type) {
switch (type) {
case MapType.satellite:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter_web
description: Web platform implementation of google_maps_flutter
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 0.5.14+3
version: 0.5.14+4

environment:
sdk: ^3.8.0
Expand Down