Skip to content

Commit 43de301

Browse files
[google_maps_flutter] Add color scheme support to app-facing package (#11280)
App-facing portion of #10471, incorporating review feedback and some other minor cleanup. Fixes flutter/flutter#176445 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent ca60bd0 commit 43de301

5 files changed

Lines changed: 51 additions & 3 deletions

File tree

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.16.0
2+
3+
* Adds `colorScheme` support for web cloud-based maps styling brightness.
4+
15
## 2.15.0
26

37
* Adds support for advanced markers, and new example pages showing their usage.

packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
4141
LatLng,
4242
LatLngBounds,
4343
MapBitmapScaling,
44+
MapColorScheme,
4445
MapStyleException,
4546
MapType,
4647
Marker,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class GoogleMap extends StatefulWidget {
144144
this.onTap,
145145
this.onLongPress,
146146
this.markerType = GoogleMapMarkerType.marker,
147+
this.colorScheme,
147148
String? mapId,
148149
@Deprecated('cloudMapId is deprecated. Use mapId instead.')
149150
String? cloudMapId,
@@ -411,6 +412,14 @@ class GoogleMap extends StatefulWidget {
411412
/// may result in unexpected behavior.
412413
final GoogleMapMarkerType markerType;
413414

415+
/// Color scheme for the cloud-style map. Web only.
416+
///
417+
/// The colorScheme option can only be set when the map is initialized;
418+
/// setting this option after the map is created will have no effect.
419+
///
420+
/// See https://developers.google.com/maps/documentation/javascript/mapcolorscheme for more details.
421+
final MapColorScheme? colorScheme;
422+
414423
/// Creates a [State] for this [GoogleMap].
415424
@override
416425
State createState() => _GoogleMapState();
@@ -767,6 +776,7 @@ MapConfiguration _configurationFromMapWidget(GoogleMap map) {
767776
trafficEnabled: map.trafficEnabled,
768777
buildingsEnabled: map.buildingsEnabled,
769778
markerType: mapConfigurationMarkerType,
779+
colorScheme: map.colorScheme,
770780
// A null mapId in the widget means no map ID, which is expressed as '' in
771781
// the configuration to distinguish from no change (null).
772782
mapId: map.mapId ?? '',

packages/google_maps_flutter/google_maps_flutter/pubspec.yaml

Lines changed: 3 additions & 3 deletions
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.15.0
5+
version: 2.16.0
66

77
environment:
88
sdk: ^3.10.0
@@ -23,8 +23,8 @@ dependencies:
2323
sdk: flutter
2424
google_maps_flutter_android: ^2.19.1
2525
google_maps_flutter_ios: ^2.18.0
26-
google_maps_flutter_platform_interface: ^2.14.2
27-
google_maps_flutter_web: ^0.6.1
26+
google_maps_flutter_platform_interface: ^2.15.0
27+
google_maps_flutter_web: ^0.6.2
2828

2929
dev_dependencies:
3030
flutter_test:

packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,39 @@ void main() {
711711
expect(map.mapConfiguration.markerType, MarkerType.marker);
712712
});
713713

714+
testWidgets('Is default color scheme null', (WidgetTester tester) async {
715+
await tester.pumpWidget(
716+
const Directionality(
717+
textDirection: TextDirection.ltr,
718+
child: GoogleMap(
719+
initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)),
720+
),
721+
),
722+
);
723+
724+
final PlatformMapStateRecorder map = platform.lastCreatedMap;
725+
726+
expect(map.mapConfiguration.colorScheme, null);
727+
});
728+
729+
testWidgets('Can set color scheme to non-default', (
730+
WidgetTester tester,
731+
) async {
732+
await tester.pumpWidget(
733+
const Directionality(
734+
textDirection: TextDirection.ltr,
735+
child: GoogleMap(
736+
initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)),
737+
colorScheme: MapColorScheme.light,
738+
),
739+
),
740+
);
741+
742+
final PlatformMapStateRecorder map = platform.lastCreatedMap;
743+
744+
expect(map.mapConfiguration.colorScheme, MapColorScheme.light);
745+
});
746+
714747
testWidgets('Can update mapId', (WidgetTester tester) async {
715748
await tester.pumpWidget(
716749
const Directionality(

0 commit comments

Comments
 (0)