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 07df4664dc2a..9f105f41499d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.2+1 + +* Fixes a bug that prevented non-cloud styles from being applied. + ## 0.6.2 * Adds `colorScheme` support for controlling cloud-based map brightness. diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/cloud_map_styles_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/cloud_map_styles_test.dart index 57555a51e457..9fd38622c105 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/cloud_map_styles_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/cloud_map_styles_test.dart @@ -26,7 +26,7 @@ void main() { textDirection: TextDirection.ltr, ); - testWidgets('cloudMapId present => mapId set & styles omitted', ( + testWidgets('cloud mapId present => mapId set & styles omitted', ( WidgetTester tester, ) async { const testMapConfig = MapConfiguration(mapId: 'test-cloud-map-id'); @@ -46,7 +46,7 @@ void main() { mapId: 1, // Internal controller ID streamController: stream, widgetConfiguration: cfg(), - mapConfiguration: testMapConfig, // cloudMapId is set here + mapConfiguration: testMapConfig, // Cloud mapId is set here ); controller.debugSetOverrides( @@ -70,13 +70,13 @@ void main() { expect( captured!.styles == null || captured!.styles!.isEmpty, isTrue, - reason: 'When cloudMapId is set, styles must not be applied.', + reason: 'When cloud mapId is set, styles must not be applied.', ); controller.dispose(); }); - testWidgets('no cloudMapId => styles applied', (WidgetTester tester) async { + testWidgets('no cloud mapId => styles applied', (WidgetTester tester) async { await tester.pumpWidget( const Directionality(textDirection: TextDirection.ltr, child: SizedBox()), ); @@ -113,13 +113,65 @@ void main() { expect( captured!.mapId, anyOf(isNull, isEmpty), - reason: 'mapId should be empty/null when no Cloud Map is used.', + reason: 'mapId should be empty/null when no cloud mapId is used.', ); expect(captured!.styles, isNotNull); expect( captured!.styles, isNotEmpty, - reason: 'When cloudMapId is null, styles should be applied.', + reason: 'When cloud mapId is null, styles should be applied.', + ); + + controller.dispose(); + }); + + testWidgets('empty cloud mapId is treated as no mapId', ( + WidgetTester tester, + ) async { + await tester.pumpWidget( + const Directionality(textDirection: TextDirection.ltr, child: SizedBox()), + ); + + final stream = StreamController>(); + addTearDown(() { + // Stream is closed by controller.dispose() + }); + + gmaps.MapOptions? captured; + final controller = GoogleMapController( + mapId: 2, // Internal controller ID + streamController: stream, + widgetConfiguration: cfg(), + mapConfiguration: const MapConfiguration(mapId: ''), + ); + + controller.debugSetOverrides( + setOptions: (gmaps.MapOptions options) { + captured = options; + }, + ); + + final styles = [ + gmaps.MapTypeStyle() + ..featureType = 'poi' + ..elementType = 'labels', + ]; + + controller.updateStyles(styles); + + await tester.pump(); + + expect(captured, isNotNull); + expect( + captured!.mapId, + anyOf(isNull, isEmpty), + reason: 'mapId should be empty/null when no cloud mapId is used.', + ); + expect(captured!.styles, isNotNull); + expect( + captured!.styles, + isNotEmpty, + reason: 'When cloud mapId is empty, styles should be applied.', ); controller.dispose(); 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 efbf2398ff49..c778ed3ce687 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 @@ -124,12 +124,15 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions( options.fullscreenControl = false; options.streetViewControl = false; + // Treat an empty mapId as null, as the app-facing package may pass it either + // way. + final String? mapId = configuration.mapId == '' ? null : configuration.mapId; // If using cloud map, do not set options.styles - if (configuration.mapId == null) { + if (mapId == null) { options.styles = styles; } - options.mapId = configuration.mapId; + options.mapId = mapId; final gmaps.ColorScheme? jsColorScheme = _gmapTypeColorSchemeForPluginColor( configuration.colorScheme, 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 423d547c4abe..4031ab5650e3 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.6.2 +version: 0.6.2+1 environment: sdk: ^3.9.0