diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md index b2c1be73c13..8c7ae71dbac 100644 --- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.14.1 +## 2.15.0 * Replaces internal use of deprecated methods. * Updates minimum supported SDK version to Flutter 3.32/Dart 3.8. @@ -6,6 +6,7 @@ versions of the endorsed platform implementations. * Applications built with older versions of Flutter will continue to use compatible versions of the platform implementations. +* Adds `colorScheme` support for web cloud-based maps styling brightness. ## 2.14.0 diff --git a/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml index 0e002e4f535..1e4a18727c4 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml @@ -33,3 +33,8 @@ flutter: uses-material-design: true assets: - assets/ +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + google_maps_flutter_platform_interface: {path: ../../../../packages/google_maps_flutter/google_maps_flutter_platform_interface} + google_maps_flutter_web: {path: ../../../../packages/google_maps_flutter/google_maps_flutter_web} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart index 7ca650dceb7..267b6cb9d77 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart @@ -41,6 +41,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf LatLng, LatLngBounds, MapBitmapScaling, + MapColorScheme, MapStyleException, MapType, Marker, diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart index 627efae290d..137c0216033 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart @@ -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. @@ -373,6 +374,14 @@ class GoogleMap extends StatefulWidget { /// for more details. final String? cloudMapId; + /// Color scheme for the cloud-style map. Web only. + /// + /// The colorScheme option can only be set when the map is initialized; + /// setting this option after the map is created will have no effect. + /// + /// See https://developers.google.com/maps/documentation/javascript/mapcolorscheme for more details. + final MapColorScheme? colorScheme; + /// Creates a [State] for this [GoogleMap]. @override State createState() => _GoogleMapState(); @@ -723,7 +732,8 @@ MapConfiguration _configurationFromMapWidget(GoogleMap map) { indoorViewEnabled: map.indoorViewEnabled, trafficEnabled: map.trafficEnabled, buildingsEnabled: map.buildingsEnabled, - mapId: map.cloudMapId, + 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 ?? '', diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index d928fb3b21f..5a5fd6b49e4 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter description: A Flutter plugin for integrating Google Maps in iOS and Android applications. repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 2.14.1 +version: 2.15.0 environment: sdk: ^3.8.0 @@ -41,3 +41,8 @@ topics: # The example deliberately includes limited-use secrets. false_secrets: - /example/web/index.html +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + google_maps_flutter_platform_interface: {path: ../../../packages/google_maps_flutter/google_maps_flutter_platform_interface} + google_maps_flutter_web: {path: ../../../packages/google_maps_flutter/google_maps_flutter_web} diff --git a/packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart b/packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart index 4aedfdbb78f..678922d8963 100644 --- a/packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart @@ -659,4 +659,37 @@ void main() { expect(map.tileOverlaySets.length, 1); }); + + testWidgets('Is default color scheme null', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), + ), + ), + ); + + final PlatformMapStateRecorder map = platform.lastCreatedMap; + + expect(map.mapConfiguration.colorScheme, null); + }); + + testWidgets('Can set color scheme to non-default', ( + WidgetTester tester, + ) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), + colorScheme: MapColorScheme.light, + ), + ), + ); + + final PlatformMapStateRecorder map = platform.lastCreatedMap; + + expect(map.mapConfiguration.colorScheme, MapColorScheme.light); + }); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md index 163cb160043..dfe0160fdc3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.15.0 + +* Adds support for `colorScheme` for cloud-based maps styling brightness in web. + ## 2.14.1 * Replaces internal use of deprecated methods. diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_color_scheme.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_color_scheme.dart new file mode 100644 index 00000000000..743d3a104a7 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_color_scheme.dart @@ -0,0 +1,15 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// The color scheme of the map to be used with cloud styles. +enum MapColorScheme { + /// The light color scheme for the map. + light, + + /// The dark color scheme for the map. + dark, + + /// The system default color scheme for the map. + followSystem, +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_configuration.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_configuration.dart index 235ec580b2e..f5f17c610a8 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_configuration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_configuration.dart @@ -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. @@ -152,6 +153,11 @@ class MapConfiguration { @Deprecated('cloudMapId is deprecated. Use mapId instead.') String? get cloudMapId => mapId; + /// Preferred color scheme for the cloud-styled map. Web only. + /// + /// See https://developers.google.com/maps/documentation/javascript/mapcolorscheme for more details. + final MapColorScheme? colorScheme; + /// Returns a new options object containing only the values of this instance /// that are different from [other]. MapConfiguration diffFrom(MapConfiguration other) { @@ -225,6 +231,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, ); @@ -264,6 +271,7 @@ class MapConfiguration { buildingsEnabled: diff.buildingsEnabled ?? buildingsEnabled, mapId: diff.mapId ?? mapId, style: diff.style ?? style, + colorScheme: diff.colorScheme ?? colorScheme, markerType: diff.markerType ?? markerType, ); } @@ -293,6 +301,7 @@ class MapConfiguration { trafficEnabled == null && buildingsEnabled == null && mapId == null && + colorScheme == null && style == null && markerType == null; @@ -329,6 +338,7 @@ class MapConfiguration { buildingsEnabled == other.buildingsEnabled && mapId == other.mapId && style == other.style && + colorScheme == other.colorScheme && markerType == other.markerType; } @@ -358,6 +368,7 @@ class MapConfiguration { buildingsEnabled, mapId, style, + colorScheme, markerType, ]); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart index a2483a24c54..80e38067433 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart @@ -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'; diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml index 9aa5ed82840..92bf349686d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/google_maps_f issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.14.1 +version: 2.15.0 environment: sdk: ^3.8.0 diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/map_configuration_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/map_configuration_test.dart index 493f5cc1393..e8564565457 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/map_configuration_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/map_configuration_test.dart @@ -485,6 +485,22 @@ void main() { // The hash code should change. expect(empty.hashCode, isNot(diff.hashCode)); }); + + test('handle colorScheme', () async { + const diff = MapConfiguration(colorScheme: MapColorScheme.followSystem); + + const empty = MapConfiguration(); + final MapConfiguration updated = diffBase.applyDiff(diff); + + // A diff applied to empty options should be the diff itself. + expect(empty.applyDiff(diff), diff); + // The diff from empty options should be the diff itself. + expect(diff.diffFrom(empty), diff); + // A diff applied to non-empty options should update that field. + expect(updated.colorScheme, MapColorScheme.followSystem); + // The hash code should change. + expect(empty.hashCode, isNot(diff.hashCode)); + }); }); group('isEmpty', () { @@ -641,5 +657,11 @@ void main() { expect(diff.isEmpty, false); }); + + test('is false with colorScheme', () async { + const diff = MapConfiguration(colorScheme: MapColorScheme.followSystem); + + expect(diff.isEmpty, false); + }); }); } diff --git a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md index 149dba55020..37f3725e114 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 0.5.15 +* Adds `colorScheme` support for web cloud-based maps styling brightness. * Updates minimum supported SDK version to Flutter 3.35/Dart 3.9. ## 0.5.14+3 diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml index a82a05b9be1..ce274faca05 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml @@ -28,9 +28,9 @@ flutter: assets: - assets/ +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins dependency_overrides: - # Override the google_maps_flutter dependency on google_maps_flutter_web. - # TODO(ditman): Unwind the circular dependency. This will create problems - # if we need to make a breaking change to google_maps_flutter_web. - google_maps_flutter_web: - path: ../ + google_maps_flutter: {path: ../../../../packages/google_maps_flutter/google_maps_flutter} + google_maps_flutter_platform_interface: {path: ../../../../packages/google_maps_flutter/google_maps_flutter_platform_interface} + google_maps_flutter_web: {path: ../} diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart index fc4d0cd0069..39fef122ca0 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart @@ -131,6 +131,14 @@ 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; } @@ -155,6 +163,23 @@ gmaps.MapTypeId _gmapTypeIDForPluginType(MapType type) { return gmaps.MapTypeId.ROADMAP; } +gmaps.ColorScheme? _gmapTypeColorSchemeForPluginColor(MapColorScheme? scheme) { + if (scheme == null) { + return null; + } + + switch (scheme) { + case MapColorScheme.dark: + return gmaps.ColorScheme.DARK; + case MapColorScheme.light: + return gmaps.ColorScheme.LIGHT; + case MapColorScheme.followSystem: + return gmaps.ColorScheme.FOLLOW_SYSTEM; + } + // ignore: dead_code + return gmaps.ColorScheme.FOLLOW_SYSTEM; +} + gmaps.MapOptions _applyInitialPosition( CameraPosition initialPosition, gmaps.MapOptions options, diff --git a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml index f87b3ea66e8..010375444ee 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -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.15 environment: sdk: ^3.9.0 @@ -40,3 +40,7 @@ topics: # The example deliberately includes limited-use secrets. false_secrets: - /example/web/index.html +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins +dependency_overrides: + google_maps_flutter_platform_interface: {path: ../../../packages/google_maps_flutter/google_maps_flutter_platform_interface}