Skip to content

Commit 1d4d137

Browse files
committed
[google_maps_flutter] Add colorScheme support for Android and iOS
Wire up MapColorScheme (light/dark/followSystem) to native APIs on both mobile platforms. The platform interface and app-facing package already support this parameter (added in 2.16.0 for web), but the Android and iOS plugins silently ignored it. Android: Uses GoogleMap.setMapColorScheme() with MapColorScheme constants. Handles both creation-time and runtime updates. iOS: Maps to UIView.overrideUserInterfaceStyle (light/dark/unspecified) on the GMSMapView, matching the Google Maps SDK for iOS documented approach. Changes per platform: - Pigeon: Add PlatformMapColorScheme enum + field on PlatformMapConfiguration - Dart: Add converter + wire into config mapper - Native: Read field, convert to native API, apply at init and on update - Tests: Convert mapper + dispatcher tests + creation-params plumbing Updates app-facing google_maps_flutter and platform_interface doc comments to reflect Android and iOS support (previously documented as "Web only"). Mirrors changes to google_maps_flutter_ios_sdk9, google_maps_flutter_ios_sdk10, and google_maps_flutter_ios_shared_code via dart tool/sync_shared_files.dart.
1 parent ade10ca commit 1d4d137

56 files changed

Lines changed: 2012 additions & 917 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.1
2+
3+
* Updates `colorScheme` doc comment to reflect Android and iOS support.
4+
15
## 2.17.0
26

37
* Adds missing re-exports of classes related to advanced markers.

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
@@ -413,10 +413,15 @@ class GoogleMap extends StatefulWidget {
413413
/// may result in unexpected behavior.
414414
final GoogleMapMarkerType markerType;
415415

416-
/// Color scheme for the cloud-style map. Web only.
416+
/// Color scheme for the map.
417417
///
418-
/// The colorScheme option can only be set when the map is initialized;
419-
/// setting this option after the map is created will have no effect.
418+
/// On Android and iOS, the color scheme can be updated after the map is
419+
/// created. On web, the value is applied only at map creation; later
420+
/// changes have no effect.
421+
///
422+
/// The map must use a cloud-based map style (via [cloudMapId]) for the
423+
/// color scheme to affect the base map tiles; otherwise the effect is
424+
/// limited to map UI chrome.
420425
///
421426
/// See https://developers.google.com/maps/documentation/javascript/mapcolorscheme for more details.
422427
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.0
5+
version: 2.17.1
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.19.9
2+
3+
* Adds `colorScheme` support for cloud-based maps styling brightness.
4+
15
## 2.19.8
26

37
* Updates internal implementation to use Kotlin Pigeon.

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)