Skip to content

Commit 233ffe6

Browse files
committed
[google_maps_flutter] Add MapColorScheme support to Android and iOS
Wires MapColorScheme (light/dark/followSystem) through to the native APIs on Android and iOS. The platform interface and app-facing package already exposed colorScheme (added in 2.16.0 for web), but the Android and iOS implementations ignored it. * Android: calls GoogleMap.setMapColorScheme() with the matching MapColorScheme constant, both at creation and on runtime configuration updates. * iOS: sets GMSMapView.overrideUserInterfaceStyle to light/dark/ unspecified, the documented Google Maps SDK for iOS approach. The iOS change is mirrored across google_maps_flutter_ios, google_maps_flutter_ios_sdk9, google_maps_flutter_ios_sdk10, and google_maps_flutter_ios_shared_code via tool/sync_shared_files.dart. The colorScheme doc comments in google_maps_flutter and google_maps_flutter_platform_interface are updated to reflect the new platform support. Adds Convert and dispatcher tests plus Dart creation-params tests on Android, parametrized creation-params tests on iOS, and a native FGMGoogleMapController test exercising the runtime color scheme update. Fixes flutter/flutter#186737
1 parent c1f7d92 commit 233ffe6

56 files changed

Lines changed: 2128 additions & 918 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.17.2
2+
3+
* Updates `colorScheme` doc comment to reflect Android and iOS support.
4+
15
## 2.17.1
26

37
* Updates README to link to implementation packages for platform-specific

packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,15 @@ class GoogleMap extends StatefulWidget {
402402
/// may result in unexpected behavior.
403403
final GoogleMapMarkerType markerType;
404404

405-
/// Color scheme for the cloud-style map. Web only.
405+
/// Color scheme for the map.
406406
///
407-
/// The colorScheme option can only be set when the map is initialized;
408-
/// setting this option after the map is created will have no effect.
407+
/// On Android and iOS, the color scheme can be updated after the map is
408+
/// created. On web, the value is applied only at map creation; later
409+
/// changes have no effect.
410+
///
411+
/// The map must use a cloud-based map style (via [mapId]) for the
412+
/// color scheme to affect the base map tiles; otherwise the effect is
413+
/// limited to map UI chrome.
409414
///
410415
/// See https://developers.google.com/maps/documentation/javascript/mapcolorscheme for more details.
411416
final MapColorScheme? colorScheme;

packages/google_maps_flutter/google_maps_flutter/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter
22
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 2.17.1
5+
version: 2.17.2
66

77
environment:
88
sdk: ^3.10.0

packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.20.0
2+
3+
* Adds `colorScheme` support for cloud-based maps styling brightness.
4+
15
## 2.19.12
26

37
* Bumps the androidx group across 10 directories with 1 update.

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,18 @@ static void interpretMapConfiguration(
577577
if (style != null) {
578578
sink.setMapStyle(style);
579579
}
580+
final PlatformMapColorScheme colorScheme = config.getColorScheme();
581+
if (colorScheme != null) {
582+
sink.setMapColorScheme(toMapColorScheme(colorScheme));
583+
}
584+
}
585+
586+
static int toMapColorScheme(@NonNull PlatformMapColorScheme colorScheme) {
587+
return switch (colorScheme) {
588+
case LIGHT -> com.google.android.gms.maps.model.MapColorScheme.LIGHT;
589+
case DARK -> com.google.android.gms.maps.model.MapColorScheme.DARK;
590+
case FOLLOW_SYSTEM -> com.google.android.gms.maps.model.MapColorScheme.FOLLOW_SYSTEM;
591+
};
580592
}
581593

582594
/** Set the options in the given object to marker options sink. */

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class GoogleMapBuilder implements GoogleMapOptionsSink {
3232
private List<PlatformGroundOverlay> initialGroundOverlays;
3333
private Rect padding = new Rect(0, 0, 0, 0);
3434
private @Nullable String style;
35+
private @Nullable Integer mapColorScheme;
3536

3637
GoogleMapController build(
3738
int id,
@@ -59,6 +60,7 @@ GoogleMapController build(
5960
controller.setInitialTileOverlays(initialTileOverlays);
6061
controller.setInitialGroundOverlays(initialGroundOverlays);
6162
controller.setMapStyle(style);
63+
controller.setMapColorScheme(mapColorScheme);
6264
return controller;
6365
}
6466

@@ -209,4 +211,9 @@ public void setInitialGroundOverlays(@NonNull List<PlatformGroundOverlay> initia
209211
public void setMapStyle(@Nullable String style) {
210212
this.style = style;
211213
}
214+
215+
@Override
216+
public void setMapColorScheme(@Nullable Integer colorScheme) {
217+
this.mapColorScheme = colorScheme;
218+
}
212219
}

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class GoogleMapController
111111
private @Nullable List<PlatformGroundOverlay> initialGroundOverlays;
112112
// Null except between initialization and onMapReady.
113113
private @Nullable String initialMapStyle;
114+
// Null except between initialization and onMapReady.
115+
private @Nullable Integer initialMapColorScheme;
114116
private boolean lastSetStyleSucceeded;
115117
@VisibleForTesting List<Float> initialPadding;
116118

@@ -245,6 +247,10 @@ public void onMapReady(@NonNull GoogleMap googleMap) {
245247
updateMapStyle(initialMapStyle);
246248
initialMapStyle = null;
247249
}
250+
if (initialMapColorScheme != null) {
251+
googleMap.setMapColorScheme(initialMapColorScheme);
252+
initialMapColorScheme = null;
253+
}
248254
}
249255

250256
// Returns the first TextureView found in the view hierarchy.
@@ -853,6 +859,17 @@ public void setMapStyle(@Nullable String style) {
853859
}
854860
}
855861

862+
public void setMapColorScheme(@Nullable Integer colorScheme) {
863+
if (colorScheme == null) {
864+
return;
865+
}
866+
if (googleMap == null) {
867+
initialMapColorScheme = colorScheme;
868+
} else {
869+
googleMap.setMapColorScheme(colorScheme);
870+
}
871+
}
872+
856873
private boolean updateMapStyle(String style) {
857874
// Dart passes an empty string to indicate that the style should be cleared.
858875
final MapStyleOptions mapStyleOptions =

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ interface GoogleMapOptionsSink {
6464
void setInitialGroundOverlays(@NonNull List<PlatformGroundOverlay> initialGroundOverlays);
6565

6666
void setMapStyle(@Nullable String style);
67+
68+
void setMapColorScheme(@Nullable Integer colorScheme);
6769
}

0 commit comments

Comments
 (0)