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 1905f2c44e9f..e062daa45430 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,5 +1,9 @@ -## NEXT +## 2.5.0 +* Adds `style` to the `MapConfiguration` to allow setting style as part of + map creation. +* Adds `getStyleError` to the platform interface, to allow asynchronous access + to style errors that occur during initialization. * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. ## 2.4.3 diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart index d9d0bb37e117..9e829c496aa4 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart @@ -362,6 +362,12 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { throw UnimplementedError('dispose() has not been implemented.'); } + /// If the last attempt to set the style via [MapConfiguration.style] failed, + /// returns the error information, otherwise returns null. + Future getStyleError({required int mapId}) async { + return null; + } + /// Returns a widget displaying the map view - deprecated, use /// [buildViewWithConfiguration] instead. Widget buildView( 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 3ec973fd7d0a..6abd6c641e86 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 @@ -36,6 +36,7 @@ class MapConfiguration { this.trafficEnabled, this.buildingsEnabled, this.cloudMapId, + this.style, }); /// This setting controls how the API handles gestures on the map. Web only. @@ -113,6 +114,11 @@ class MapConfiguration { /// for more details. final String? cloudMapId; + /// Locally configured JSON style. + /// + /// To clear a previously set style, set this to an empty string. + final String? style; + /// Returns a new options object containing only the values of this instance /// that are different from [other]. MapConfiguration diffFrom(MapConfiguration other) { @@ -174,6 +180,7 @@ class MapConfiguration { buildingsEnabled: buildingsEnabled != other.buildingsEnabled ? buildingsEnabled : null, cloudMapId: cloudMapId != other.cloudMapId ? cloudMapId : null, + style: style != other.style ? style : null, ); } @@ -206,6 +213,7 @@ class MapConfiguration { trafficEnabled: diff.trafficEnabled ?? trafficEnabled, buildingsEnabled: diff.buildingsEnabled ?? buildingsEnabled, cloudMapId: diff.cloudMapId ?? cloudMapId, + style: diff.style ?? style, ); } @@ -231,7 +239,8 @@ class MapConfiguration { indoorViewEnabled == null && trafficEnabled == null && buildingsEnabled == null && - cloudMapId == null; + cloudMapId == null && + style == null; @override bool operator ==(Object other) { @@ -262,7 +271,8 @@ class MapConfiguration { indoorViewEnabled == other.indoorViewEnabled && trafficEnabled == other.trafficEnabled && buildingsEnabled == other.buildingsEnabled && - cloudMapId == other.cloudMapId; + cloudMapId == other.cloudMapId && + style == other.style; } @override @@ -288,5 +298,6 @@ class MapConfiguration { trafficEnabled, buildingsEnabled, cloudMapId, + style, ]); } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/map_configuration_serialization.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/map_configuration_serialization.dart index 3c3e0b714cb6..43b25fa642da 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/map_configuration_serialization.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/map_configuration_serialization.dart @@ -59,5 +59,6 @@ Map jsonForMapConfiguration(MapConfiguration config) { if (config.buildingsEnabled != null) 'buildingsEnabled': config.buildingsEnabled!, if (config.cloudMapId != null) 'cloudMapId': config.cloudMapId!, + if (config.style != null) 'style': config.style!, }; } 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 2f30c38978f5..8a712be78a77 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.4.3 +version: 2.5.0 environment: sdk: ^3.1.0 diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart index d1dba2b75b55..798559a68f0a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/platform_interface/google_maps_flutter_platform_test.dart @@ -83,6 +83,15 @@ void main() { ); }, ); + + test( + 'default implementation of `getStyleError` returns null', + () async { + final GoogleMapsFlutterPlatform platform = + BuildViewGoogleMapsFlutterPlatform(); + expect(await platform.getStyleError(mapId: 0), null); + }, + ); }); } 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 2a53b8c0bbc6..e34f32676e0a 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 @@ -33,6 +33,7 @@ void main() { indoorViewEnabled: false, trafficEnabled: false, buildingsEnabled: false, + style: 'diff base style', ); test('only include changed fields', () async { @@ -408,6 +409,23 @@ void main() { // The hash code should change. expect(empty.hashCode, isNot(diff.hashCode)); }); + + test('handle style', () async { + const String aStlye = 'a style'; + const MapConfiguration diff = MapConfiguration(style: aStlye); + + const MapConfiguration 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.style, aStlye); + // The hash code should change. + expect(empty.hashCode, isNot(diff.hashCode)); + }); }); group('isEmpty', () { @@ -541,5 +559,11 @@ void main() { expect(diff.isEmpty, false); }); + + test('is false with style', () async { + const MapConfiguration diff = MapConfiguration(style: 'a style'); + + expect(diff.isEmpty, false); + }); }); }