From 15539cc80c413160f1c41ee438aeb34e76d9e617 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 6 Feb 2024 14:01:44 -0500 Subject: [PATCH 01/16] Adjust example app for visual repro --- .../shared/maps_example_dart/lib/map_ui.dart | 167 +++++++++++++++++- 1 file changed, 166 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart index 311e2267aa0c..47b6d9508a8d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart @@ -11,6 +11,170 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf import 'example_google_map.dart'; import 'page.dart'; +const String _nightModeStyle = ''' +[ + { + "elementType": "geometry", + "stylers": [ + { + "color": "#242f3e" + } + ] + }, + { + "elementType": "labels.text.fill", + "stylers": [ + { + "color": "#746855" + } + ] + }, + { + "elementType": "labels.text.stroke", + "stylers": [ + { + "color": "#242f3e" + } + ] + }, + { + "featureType": "administrative.locality", + "elementType": "labels.text.fill", + "stylers": [ + { + "color": "#d59563" + } + ] + }, + { + "featureType": "poi", + "elementType": "labels.text.fill", + "stylers": [ + { + "color": "#d59563" + } + ] + }, + { + "featureType": "poi.park", + "elementType": "geometry", + "stylers": [ + { + "color": "#263c3f" + } + ] + }, + { + "featureType": "poi.park", + "elementType": "labels.text.fill", + "stylers": [ + { + "color": "#6b9a76" + } + ] + }, + { + "featureType": "road", + "elementType": "geometry", + "stylers": [ + { + "color": "#38414e" + } + ] + }, + { + "featureType": "road", + "elementType": "geometry.stroke", + "stylers": [ + { + "color": "#212a37" + } + ] + }, + { + "featureType": "road", + "elementType": "labels.text.fill", + "stylers": [ + { + "color": "#9ca5b3" + } + ] + }, + { + "featureType": "road.highway", + "elementType": "geometry", + "stylers": [ + { + "color": "#746855" + } + ] + }, + { + "featureType": "road.highway", + "elementType": "geometry.stroke", + "stylers": [ + { + "color": "#1f2835" + } + ] + }, + { + "featureType": "road.highway", + "elementType": "labels.text.fill", + "stylers": [ + { + "color": "#f3d19c" + } + ] + }, + { + "featureType": "transit", + "elementType": "geometry", + "stylers": [ + { + "color": "#2f3948" + } + ] + }, + { + "featureType": "transit.station", + "elementType": "labels.text.fill", + "stylers": [ + { + "color": "#d59563" + } + ] + }, + { + "featureType": "water", + "elementType": "geometry", + "stylers": [ + { + "color": "#17263c" + } + ] + }, + { + "featureType": "water", + "elementType": "labels.text.fill", + "stylers": [ + { + "color": "#515c6d" + } + ] + }, + { + "featureType": "water", + "elementType": "labels.text.stroke", + "stylers": [ + { + "color": "#17263c" + } + ] + } +] +'''; + final LatLngBounds sydneyBounds = LatLngBounds( southwest: const LatLng(-34.022631, 150.620685), northeast: const LatLng(-33.571835, 151.325952), @@ -263,7 +427,7 @@ class MapUiBodyState extends State { _controller.setMapStyle(null); }); } else { - _getFileData('assets/night_mode.json').then(_setMapStyle); + _setMapStyle(_nightModeStyle); } }, ); @@ -353,5 +517,6 @@ class MapUiBodyState extends State { _controller = controller; _isMapCreated = true; }); + _setMapStyle(_nightModeStyle); } } From fc93d0b791237666c0f2304b63ee3cec36ccf378 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 6 Feb 2024 14:03:15 -0500 Subject: [PATCH 02/16] WIP --- .../google_maps_flutter/lib/src/google_map.dart | 4 ++++ 1 file changed, 4 insertions(+) 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 3b73e55664dd..dd55104cb3be 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 @@ -91,6 +91,7 @@ class GoogleMap extends StatefulWidget { const GoogleMap({ super.key, required this.initialCameraPosition, + this.initialMapStyle, this.onMapCreated, this.gestureRecognizers = const >{}, this.webGestureHandling, @@ -136,6 +137,9 @@ class GoogleMap extends StatefulWidget { /// The initial position of the map's camera. final CameraPosition initialCameraPosition; + /// The initial map style used when the controller is created. + final String? initialMapStyle; + /// True if the map should show a compass when rotated. final bool compassEnabled; From fedcb40c7908ba2af4a0c763dfa4fa3688f746bb Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 6 Feb 2024 14:03:27 -0500 Subject: [PATCH 03/16] Pathify platform interface --- .../google_maps_flutter/example/pubspec.yaml | 5 +++++ .../google_maps_flutter/google_maps_flutter/pubspec.yaml | 5 +++++ .../google_maps_flutter_android/example/pubspec.yaml | 5 +++++ .../google_maps_flutter_android/pubspec.yaml | 5 +++++ .../google_maps_flutter_ios/example/ios12/pubspec.yaml | 5 +++++ .../google_maps_flutter_ios/example/ios13/pubspec.yaml | 5 +++++ .../google_maps_flutter_ios/example/ios14/pubspec.yaml | 5 +++++ .../example/shared/maps_example_dart/pubspec.yaml | 5 +++++ .../google_maps_flutter_ios/pubspec.yaml | 5 +++++ .../google_maps_flutter_web/example/pubspec.yaml | 6 ++++++ .../google_maps_flutter_web/pubspec.yaml | 5 +++++ 11 files changed, 56 insertions(+) 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 efed14ceecbf..7890b777dd0a 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/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 9b53f596fdf6..a504638e2a05 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -40,3 +40,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/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_android/example/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_android/example/pubspec.yaml index f241ddc6c920..ef32aa1c8da6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/example/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_android/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/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml index 30b1644e313c..b48aed86b9a3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml @@ -34,3 +34,8 @@ topics: - google-maps - google-maps-flutter - map + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/pubspec.yaml index e5e0cd2a4b1e..846b5cf22208 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/pubspec.yaml @@ -32,3 +32,8 @@ flutter: uses-material-design: true assets: - assets/ + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/pubspec.yaml index e5e0cd2a4b1e..846b5cf22208 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/pubspec.yaml @@ -32,3 +32,8 @@ flutter: uses-material-design: true assets: - assets/ + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/pubspec.yaml index e5e0cd2a4b1e..846b5cf22208 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/pubspec.yaml @@ -32,3 +32,8 @@ flutter: uses-material-design: true assets: - assets/ + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/pubspec.yaml index 38259978c902..6ccbe4fe2a08 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/pubspec.yaml @@ -27,3 +27,8 @@ dev_dependencies: flutter: uses-material-design: true + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml index 502db892ac53..09b028bb9509 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml @@ -32,3 +32,8 @@ topics: - google-maps - google-maps-flutter - map + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface}} 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 7b2c31b6f537..d3b66d667ef1 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 @@ -24,9 +24,15 @@ dev_dependencies: sdk: flutter mockito: 5.4.4 + +# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. +# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#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_platform_interface: + path: ../../../google_maps_flutter/google_maps_flutter_platform_interface google_maps_flutter_web: path: ../ 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 2293fe78c14a..3562c8e30575 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -39,3 +39,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/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins +dependency_overrides: + {google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface}} From 1dddbb05060f5dee2b6a067fab1eb4722dc04e94 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 22 Feb 2024 10:51:48 -0500 Subject: [PATCH 04/16] Add style support to MapConfiguration --- .../lib/src/types/map_configuration.dart | 13 ++++++++-- .../map_configuration_serialization.dart | 1 + .../test/types/map_configuration_test.dart | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) 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..a4b1e2c04d6b 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,9 @@ class MapConfiguration { /// for more details. final String? cloudMapId; + /// Locally configured JSON style. + 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 +178,7 @@ class MapConfiguration { buildingsEnabled: buildingsEnabled != other.buildingsEnabled ? buildingsEnabled : null, cloudMapId: cloudMapId != other.cloudMapId ? cloudMapId : null, + style: style != other.style ? style : null, ); } @@ -206,6 +211,7 @@ class MapConfiguration { trafficEnabled: diff.trafficEnabled ?? trafficEnabled, buildingsEnabled: diff.buildingsEnabled ?? buildingsEnabled, cloudMapId: diff.cloudMapId ?? cloudMapId, + style: diff.style ?? style, ); } @@ -231,7 +237,8 @@ class MapConfiguration { indoorViewEnabled == null && trafficEnabled == null && buildingsEnabled == null && - cloudMapId == null; + cloudMapId == null && + style == null; @override bool operator ==(Object other) { @@ -262,7 +269,8 @@ class MapConfiguration { indoorViewEnabled == other.indoorViewEnabled && trafficEnabled == other.trafficEnabled && buildingsEnabled == other.buildingsEnabled && - cloudMapId == other.cloudMapId; + cloudMapId == other.cloudMapId && + style == other.style; } @override @@ -288,5 +296,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/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); + }); }); } From 2434a00cfb562ab6b417b771dc2d49a4574a9b83 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 22 Feb 2024 13:20:50 -0500 Subject: [PATCH 05/16] Add getStyleError --- .../integration_test/google_maps_test.dart | 57 ++++++++++++++++++- .../lib/example_google_map.dart | 16 ++++-- .../shared/maps_example_dart/lib/map_ui.dart | 30 ++++------ .../ios/Classes/GoogleMapController.m | 21 +++++-- .../lib/src/google_maps_flutter_ios.dart | 7 +++ .../google_maps_flutter_platform.dart | 6 ++ .../google_maps_flutter_platform_test.dart | 9 +++ 7 files changed, 113 insertions(+), 33 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/integration_test/google_maps_test.dart b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/integration_test/google_maps_test.dart index 9902456444d6..9ebc5cdd4835 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/integration_test/google_maps_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/integration_test/google_maps_test.dart @@ -583,7 +583,8 @@ void main() { await controllerCompleter.future; const String mapStyle = '[{"elementType":"geometry","stylers":[{"color":"#242f3e"}]}]'; - await controller.setMapStyle(mapStyle); + await GoogleMapsFlutterPlatform.instance + .setMapStyle(mapStyle, mapId: controller.mapId); }); testWidgets('testSetMapStyle invalid Json String', @@ -607,7 +608,8 @@ void main() { await controllerCompleter.future; try { - await controller.setMapStyle('invalid_value'); + await GoogleMapsFlutterPlatform.instance + .setMapStyle('invalid_value', mapId: controller.mapId); fail('expected MapStyleException'); } on MapStyleException catch (e) { expect(e.cause, isNotNull); @@ -632,7 +634,8 @@ void main() { final ExampleGoogleMapController controller = await controllerCompleter.future; - await controller.setMapStyle(null); + await GoogleMapsFlutterPlatform.instance + .setMapStyle(null, mapId: controller.mapId); }); testWidgets('testGetLatLng', (WidgetTester tester) async { @@ -1048,6 +1051,54 @@ void main() { ), )); }); + + testWidgets('getStyleError reports last error', (WidgetTester tester) async { + final Key key = GlobalKey(); + final Completer controllerCompleter = + Completer(); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: ExampleGoogleMap( + key: key, + initialCameraPosition: _kInitialCameraPosition, + style: '[[[this is an invalid style', + onMapCreated: (ExampleGoogleMapController controller) { + controllerCompleter.complete(controller); + }, + ), + )); + + final ExampleGoogleMapController controller = + await controllerCompleter.future; + final String? error = await controller.getStyleError(); + expect(error, isNotNull); + }); + + testWidgets('getStyleError returns null for a valid style', + (WidgetTester tester) async { + final Key key = GlobalKey(); + final Completer controllerCompleter = + Completer(); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: ExampleGoogleMap( + key: key, + initialCameraPosition: _kInitialCameraPosition, + // An empty array is the simplest valid style. + style: '[]', + onMapCreated: (ExampleGoogleMapController controller) { + controllerCompleter.complete(controller); + }, + ), + )); + + final ExampleGoogleMapController controller = + await controllerCompleter.future; + final String? error = await controller.getStyleError(); + expect(error, isNull); + }); } class _DebugTileProvider implements TileProvider { diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/example_google_map.dart b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/example_google_map.dart index f176b987e28b..0734731af7c3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/example_google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/example_google_map.dart @@ -144,12 +144,6 @@ class ExampleGoogleMapController { .moveCamera(cameraUpdate, mapId: mapId); } - /// Sets the styling of the base map. - Future setMapStyle(String? mapStyle) { - return GoogleMapsFlutterPlatform.instance - .setMapStyle(mapStyle, mapId: mapId); - } - /// Return [LatLngBounds] defining the region that is visible in a map. Future getVisibleRegion() { return GoogleMapsFlutterPlatform.instance.getVisibleRegion(mapId: mapId); @@ -195,6 +189,11 @@ class ExampleGoogleMapController { return GoogleMapsFlutterPlatform.instance.takeSnapshot(mapId: mapId); } + /// Returns the last style error, if any. + Future getStyleError() { + return GoogleMapsFlutterPlatform.instance.getStyleError(mapId: mapId); + } + /// Disposes of the platform resources void dispose() { GoogleMapsFlutterPlatform.instance.dispose(mapId: mapId); @@ -245,6 +244,7 @@ class ExampleGoogleMap extends StatefulWidget { this.onTap, this.onLongPress, this.cloudMapId, + this.style, }); /// Callback method for when the map is ready to be used. @@ -353,6 +353,9 @@ class ExampleGoogleMap extends StatefulWidget { /// for more details. final String? cloudMapId; + /// The locally configured style for the map. + final String? style; + /// Creates a [State] for this [ExampleGoogleMap]. @override State createState() => _ExampleGoogleMapState(); @@ -539,5 +542,6 @@ MapConfiguration _configurationFromMapWidget(ExampleGoogleMap map) { trafficEnabled: map.trafficEnabled, buildingsEnabled: map.buildingsEnabled, cloudMapId: map.cloudMapId, + style: map.style, ); } diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart index 47b6d9508a8d..3cdb6de621f5 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart @@ -223,7 +223,7 @@ class MapUiBodyState extends State { bool _myTrafficEnabled = false; bool _myLocationButtonEnabled = true; late ExampleGoogleMapController _controller; - bool _nightMode = false; + bool _nightMode = true; @override void initState() { @@ -408,27 +408,13 @@ class MapUiBodyState extends State { return rootBundle.loadString(path); } - void _setMapStyle(String mapStyle) { - setState(() { - _nightMode = true; - _controller.setMapStyle(mapStyle); - }); - } - - // Should only be called if _isMapCreated is true. Widget _nightModeToggler() { - assert(_isMapCreated); return TextButton( child: Text('${_nightMode ? 'disable' : 'enable'} night mode'), onPressed: () { - if (_nightMode) { - setState(() { - _nightMode = false; - _controller.setMapStyle(null); - }); - } else { - _setMapStyle(_nightModeStyle); - } + setState(() { + _nightMode = !_nightMode; + }); }, ); } @@ -443,6 +429,7 @@ class MapUiBodyState extends State { cameraTargetBounds: _cameraTargetBounds, minMaxZoomPreference: _minMaxZoomPreference, mapType: _mapType, + style: _nightMode ? _nightModeStyle : '', rotateGesturesEnabled: _rotateGesturesEnabled, scrollGesturesEnabled: _scrollGesturesEnabled, tiltGesturesEnabled: _tiltGesturesEnabled, @@ -517,6 +504,11 @@ class MapUiBodyState extends State { _controller = controller; _isMapCreated = true; }); - _setMapStyle(_nightModeStyle); + // Log any style errors to the console for debugging. + _controller.getStyleError().then((String? error) { + if (error != null) { + debugPrint(error); + } + }); } } diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m index 06e7838d9f4d..b619527fa95c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m @@ -67,6 +67,11 @@ @interface FLTGoogleMapController () @property(nonatomic, strong) FLTPolylinesController *polylinesController; @property(nonatomic, strong) FLTCirclesController *circlesController; @property(nonatomic, strong) FLTTileOverlaysController *tileOverlaysController; +// The resulting error message, if any, from the last attempt to set the map style. +// This is used to provide access to errors after the fact, since the map style is generally set at +// creation time and there's no mechanism to return non-fatal error details during platform view +// initialization. +@property(nonatomic, copy) NSString *styleError; @end @@ -400,13 +405,15 @@ - (void)onMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { NSNumber *isBuildingsEnabled = @(self.mapView.buildingsEnabled); result(isBuildingsEnabled); } else if ([call.method isEqualToString:@"map#setStyle"]) { - NSString *mapStyle = [call arguments]; - NSString *error = [self setMapStyle:mapStyle]; - if (error == nil) { + id mapStyle = [call arguments]; + self.styleError = [self setMapStyle:(mapStyle == [NSNull null] ? nil : mapStyle)]; + if (self.styleError == nil) { result(@[ @(YES) ]); } else { - result(@[ @(NO), error ]); + result(@[ @(NO), self.styleError ]); } + } else if ([call.method isEqualToString:@"map#getStyleError"]) { + result(self.styleError); } else if ([call.method isEqualToString:@"map#getTileOverlayInfo"]) { NSString *rawTileOverlayId = call.arguments[@"tileOverlayId"]; result([self.tileOverlaysController tileOverlayInfoWithIdentifier:rawTileOverlayId]); @@ -506,7 +513,7 @@ - (void)setMyLocationButtonEnabled:(BOOL)enabled { } - (NSString *)setMapStyle:(NSString *)mapStyle { - if (mapStyle == (id)[NSNull null] || mapStyle.length == 0) { + if (mapStyle.length == 0) { self.mapView.mapStyle = nil; return nil; } @@ -658,6 +665,10 @@ - (void)interpretMapOptions:(NSDictionary *)data { if (myLocationButtonEnabled && myLocationButtonEnabled != (id)[NSNull null]) { [self setMyLocationButtonEnabled:[myLocationButtonEnabled boolValue]]; } + NSString* style = data[@"style"]; + if (style) { + self.styleError = [self setMapStyle:style]; + } } @end diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/google_maps_flutter_ios.dart b/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/google_maps_flutter_ios.dart index 642febcdd3b9..56f3cc5a0794 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/google_maps_flutter_ios.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/lib/src/google_maps_flutter_ios.dart @@ -466,6 +466,12 @@ class GoogleMapsFlutterIOS extends GoogleMapsFlutterPlatform { return _channel(mapId).invokeMethod('map#takeSnapshot'); } + @override + Future getStyleError({required int mapId}) { + final MethodChannel channel = ensureChannelInitialized(mapId); + return channel.invokeMethod('map#getStyleError'); + } + Widget _buildView( int creationId, PlatformViewCreatedCallback onPlatformViewCreated, { @@ -618,6 +624,7 @@ 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/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/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..5e0d7921fb8f 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(), null); + }, + ); }); } From e0355dff6566220f23b52dd5be5b5059ecc4da66 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 22 Feb 2024 16:30:30 -0500 Subject: [PATCH 06/16] Android implementation --- .../flutter/plugins/googlemaps/Convert.java | 4 ++ .../plugins/googlemaps/GoogleMapBuilder.java | 10 +++ .../googlemaps/GoogleMapController.java | 62 ++++++++++++------- .../googlemaps/GoogleMapOptionsSink.java | 4 ++ .../integration_test/google_maps_tests.dart | 62 ++++++++++++++++++- .../example/lib/example_google_map.dart | 16 +++-- .../example/lib/map_ui.dart | 33 +++++----- .../lib/src/google_maps_flutter_android.dart | 6 ++ 8 files changed, 149 insertions(+), 48 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java index 78c7dc2428c6..b473f1ea17d8 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java @@ -377,6 +377,10 @@ static void interpretGoogleMapOptions(Object o, GoogleMapOptionsSink sink) { if (buildingsEnabled != null) { sink.setBuildingsEnabled(toBoolean(buildingsEnabled)); } + final Object style = data.get("style"); + if (style != null) { + sink.setMapStyle(toString(style)); + } } /** Returns the dartMarkerId of the interpreted marker. */ diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java index fa82b77743d2..4f167b583809 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java @@ -6,6 +6,9 @@ import android.content.Context; import android.graphics.Rect; + +import androidx.annotation.Nullable; + import com.google.android.gms.maps.GoogleMapOptions; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLngBounds; @@ -27,6 +30,7 @@ class GoogleMapBuilder implements GoogleMapOptionsSink { private Object initialCircles; private List> initialTileOverlays; private Rect padding = new Rect(0, 0, 0, 0); + private @Nullable String style; GoogleMapController build( int id, @@ -48,6 +52,7 @@ GoogleMapController build( controller.setInitialCircles(initialCircles); controller.setPadding(padding.top, padding.left, padding.bottom, padding.right); controller.setInitialTileOverlays(initialTileOverlays); + controller.setMapStyle(style); return controller; } @@ -178,4 +183,9 @@ public void setInitialCircles(Object initialCircles) { public void setInitialTileOverlays(List> initialTileOverlays) { this.initialTileOverlays = initialTileOverlays; } + + @Override + public void setMapStyle(@Nullable String style) { + this.style = style; + } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index 917d45218345..4aba93940e68 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -48,6 +48,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** Controller of a single GoogleMaps MapView instance. */ final class GoogleMapController @@ -87,6 +88,9 @@ final class GoogleMapController private List initialPolylines; private List initialCircles; private List> initialTileOverlays; + // Null except between initialization and onMapReady. + private @Nullable String initialMapStyle; + private @Nullable String lastStyleError; @VisibleForTesting List initialPadding; GoogleMapController( @@ -169,6 +173,10 @@ public void onMapReady(GoogleMap googleMap) { initialPadding.get(2), initialPadding.get(3)); } + if (initialMapStyle != null) { + updateMapStyle(initialMapStyle); + initialMapStyle = null; + } } // Returns the first TextureView found in the view hierarchy. @@ -458,27 +466,23 @@ public void onSnapshotReady(Bitmap bitmap) { break; } case "map#setStyle": - { - boolean mapStyleSet; - if (call.arguments instanceof String) { - String mapStyle = (String) call.arguments; - if (mapStyle == null) { - mapStyleSet = googleMap.setMapStyle(null); - } else { - mapStyleSet = googleMap.setMapStyle(new MapStyleOptions(mapStyle)); - } - } else { - mapStyleSet = googleMap.setMapStyle(null); - } - ArrayList mapStyleResult = new ArrayList<>(2); - mapStyleResult.add(mapStyleSet); - if (!mapStyleSet) { - mapStyleResult.add( - "Unable to set the map style. Please check console logs for errors."); - } - result.success(mapStyleResult); - break; - } + { + Object arg = call.arguments; + final String style = arg instanceof String ? (String) arg : null; + final boolean mapStyleSet = updateMapStyle(style); + ArrayList mapStyleResult = new ArrayList<>(2); + mapStyleResult.add(mapStyleSet); + if (!mapStyleSet) { + mapStyleResult.add(lastStyleError); + } + result.success(mapStyleResult); + break; + } + case "map#getStyleError": + { + result.success(lastStyleError); + break; + } case "tileOverlays#update": { List> tileOverlaysToAdd = call.argument("tileOverlaysToAdd"); @@ -926,4 +930,20 @@ public void setTrafficEnabled(boolean trafficEnabled) { public void setBuildingsEnabled(boolean buildingsEnabled) { this.buildingsEnabled = buildingsEnabled; } + + public void setMapStyle(@Nullable String style) { + if (googleMap == null) { + initialMapStyle = style; + } else { + updateMapStyle(style); + } + } + + private boolean updateMapStyle(String style) { + // Dart passes an empty string to indicate that the style should be cleared. + final MapStyleOptions mapStyleOptions = style == null || style.isEmpty() ? null : new MapStyleOptions(style); + final boolean set = Objects.requireNonNull(googleMap).setMapStyle(mapStyleOptions); + lastStyleError = set ? null : "Unable to set the map style. Please check console logs for errors."; + return set; + } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java index 17f0d970a4ef..34cfc1f7aeb1 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java @@ -4,6 +4,8 @@ package io.flutter.plugins.googlemaps; +import androidx.annotation.Nullable; + import com.google.android.gms.maps.model.LatLngBounds; import java.util.List; import java.util.Map; @@ -55,4 +57,6 @@ interface GoogleMapOptionsSink { void setInitialCircles(Object initialCircles); void setInitialTileOverlays(List> initialTileOverlays); + + void setMapStyle(@Nullable String style); } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/google_maps_tests.dart b/packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/google_maps_tests.dart index 97e7dfa0a37e..e03fe8f8851b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/google_maps_tests.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/google_maps_tests.dart @@ -722,7 +722,8 @@ void googleMapsTests() { await controllerCompleter.future; const String mapStyle = '[{"elementType":"geometry","stylers":[{"color":"#242f3e"}]}]'; - await controller.setMapStyle(mapStyle); + await GoogleMapsFlutterPlatform.instance + .setMapStyle(mapStyle, mapId: controller.mapId); }); testWidgets('testSetMapStyle invalid Json String', @@ -746,10 +747,12 @@ void googleMapsTests() { await controllerCompleter.future; try { - await controller.setMapStyle('invalid_value'); + await GoogleMapsFlutterPlatform.instance + .setMapStyle('invalid_value', mapId: controller.mapId); fail('expected MapStyleException'); } on MapStyleException catch (e) { expect(e.cause, isNotNull); + expect(await controller.getStyleError(), isNotNull); } }); @@ -771,7 +774,8 @@ void googleMapsTests() { final ExampleGoogleMapController controller = await controllerCompleter.future; - await controller.setMapStyle(null); + await GoogleMapsFlutterPlatform.instance + .setMapStyle(null, mapId: controller.mapId); }); testWidgets('testGetLatLng', (WidgetTester tester) async { @@ -1211,6 +1215,58 @@ void googleMapsTests() { await mapIdCompleter.future; }, ); + + testWidgets('getStyleError reports last error', (WidgetTester tester) async { + final Key key = GlobalKey(); + final Completer controllerCompleter = + Completer(); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: ExampleGoogleMap( + key: key, + initialCameraPosition: _kInitialCameraPosition, + style: '[[[this is an invalid style', + onMapCreated: (ExampleGoogleMapController controller) { + controllerCompleter.complete(controller); + }, + ), + )); + + final ExampleGoogleMapController controller = + await controllerCompleter.future; + String? error = await controller.getStyleError(); + for (int i = 0; i < 1000 && error == null; i++) { + await Future.delayed(const Duration(milliseconds: 10)); + error = await controller.getStyleError(); + } + expect(error, isNotNull); + }); + + testWidgets('getStyleError returns null for a valid style', + (WidgetTester tester) async { + final Key key = GlobalKey(); + final Completer controllerCompleter = + Completer(); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: ExampleGoogleMap( + key: key, + initialCameraPosition: _kInitialCameraPosition, + // An empty array is the simplest valid style. + style: '[]', + onMapCreated: (ExampleGoogleMapController controller) { + controllerCompleter.complete(controller); + }, + ), + )); + + final ExampleGoogleMapController controller = + await controllerCompleter.future; + final String? error = await controller.getStyleError(); + expect(error, isNull); + }); } class _DebugTileProvider implements TileProvider { diff --git a/packages/google_maps_flutter/google_maps_flutter_android/example/lib/example_google_map.dart b/packages/google_maps_flutter/google_maps_flutter_android/example/lib/example_google_map.dart index f176b987e28b..0734731af7c3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/example/lib/example_google_map.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/example/lib/example_google_map.dart @@ -144,12 +144,6 @@ class ExampleGoogleMapController { .moveCamera(cameraUpdate, mapId: mapId); } - /// Sets the styling of the base map. - Future setMapStyle(String? mapStyle) { - return GoogleMapsFlutterPlatform.instance - .setMapStyle(mapStyle, mapId: mapId); - } - /// Return [LatLngBounds] defining the region that is visible in a map. Future getVisibleRegion() { return GoogleMapsFlutterPlatform.instance.getVisibleRegion(mapId: mapId); @@ -195,6 +189,11 @@ class ExampleGoogleMapController { return GoogleMapsFlutterPlatform.instance.takeSnapshot(mapId: mapId); } + /// Returns the last style error, if any. + Future getStyleError() { + return GoogleMapsFlutterPlatform.instance.getStyleError(mapId: mapId); + } + /// Disposes of the platform resources void dispose() { GoogleMapsFlutterPlatform.instance.dispose(mapId: mapId); @@ -245,6 +244,7 @@ class ExampleGoogleMap extends StatefulWidget { this.onTap, this.onLongPress, this.cloudMapId, + this.style, }); /// Callback method for when the map is ready to be used. @@ -353,6 +353,9 @@ class ExampleGoogleMap extends StatefulWidget { /// for more details. final String? cloudMapId; + /// The locally configured style for the map. + final String? style; + /// Creates a [State] for this [ExampleGoogleMap]. @override State createState() => _ExampleGoogleMapState(); @@ -539,5 +542,6 @@ MapConfiguration _configurationFromMapWidget(ExampleGoogleMap map) { trafficEnabled: map.trafficEnabled, buildingsEnabled: map.buildingsEnabled, cloudMapId: map.cloudMapId, + style: map.style, ); } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_ui.dart b/packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_ui.dart index 311e2267aa0c..105676da9ed5 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_ui.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/example/lib/map_ui.dart @@ -60,6 +60,7 @@ class MapUiBodyState extends State { bool _myLocationButtonEnabled = true; late ExampleGoogleMapController _controller; bool _nightMode = false; + String _mapStyle = ''; @override void initState() { @@ -244,27 +245,16 @@ class MapUiBodyState extends State { return rootBundle.loadString(path); } - void _setMapStyle(String mapStyle) { - setState(() { - _nightMode = true; - _controller.setMapStyle(mapStyle); - }); - } - - // Should only be called if _isMapCreated is true. Widget _nightModeToggler() { - assert(_isMapCreated); return TextButton( child: Text('${_nightMode ? 'disable' : 'enable'} night mode'), - onPressed: () { - if (_nightMode) { - setState(() { - _nightMode = false; - _controller.setMapStyle(null); - }); - } else { - _getFileData('assets/night_mode.json').then(_setMapStyle); - } + onPressed: () async { + _nightMode = !_nightMode; + final String style = + _nightMode ? await _getFileData('assets/night_mode.json') : ''; + setState(() { + _mapStyle = style; + }); }, ); } @@ -279,6 +269,7 @@ class MapUiBodyState extends State { cameraTargetBounds: _cameraTargetBounds, minMaxZoomPreference: _minMaxZoomPreference, mapType: _mapType, + style: _mapStyle, rotateGesturesEnabled: _rotateGesturesEnabled, scrollGesturesEnabled: _scrollGesturesEnabled, tiltGesturesEnabled: _tiltGesturesEnabled, @@ -353,5 +344,11 @@ class MapUiBodyState extends State { _controller = controller; _isMapCreated = true; }); + // Log any style errors to the console for debugging. + _controller.getStyleError().then((String? error) { + if (error != null) { + debugPrint(error); + } + }); } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart index 4cb87722f375..d40d795d6a32 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart @@ -484,6 +484,11 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform { return _channel(mapId).invokeMethod('map#takeSnapshot'); } + @override + Future getStyleError({required int mapId}) { + return _channel(mapId).invokeMethod('map#getStyleError'); + } + /// Set [GoogleMapsFlutterPlatform] to use [AndroidViewSurface] to build the /// Google Maps widget. /// @@ -727,6 +732,7 @@ 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!, }; } From be284f3e1ad18ca6038b4214fdf2bba1d65e3b40 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 22 Feb 2024 16:30:56 -0500 Subject: [PATCH 07/16] Improve documentation --- .../lib/src/types/map_configuration.dart | 2 ++ 1 file changed, 2 insertions(+) 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 a4b1e2c04d6b..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 @@ -115,6 +115,8 @@ class MapConfiguration { 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 From 22837ba33ae3be0ed0ac69d197411eb21d9b118c Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 22 Feb 2024 16:31:04 -0500 Subject: [PATCH 08/16] Clean up iOS example changes --- .../integration_test/google_maps_test.dart | 1 + .../shared/maps_example_dart/lib/map_ui.dart | 176 +----------------- 2 files changed, 9 insertions(+), 168 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/integration_test/google_maps_test.dart b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/integration_test/google_maps_test.dart index 9ebc5cdd4835..e49c451d08ee 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/integration_test/google_maps_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/integration_test/google_maps_test.dart @@ -613,6 +613,7 @@ void main() { fail('expected MapStyleException'); } on MapStyleException catch (e) { expect(e.cause, isNotNull); + expect(await controller.getStyleError(), isNotNull); } }); diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart index 3cdb6de621f5..105676da9ed5 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/map_ui.dart @@ -11,170 +11,6 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf import 'example_google_map.dart'; import 'page.dart'; -const String _nightModeStyle = ''' -[ - { - "elementType": "geometry", - "stylers": [ - { - "color": "#242f3e" - } - ] - }, - { - "elementType": "labels.text.fill", - "stylers": [ - { - "color": "#746855" - } - ] - }, - { - "elementType": "labels.text.stroke", - "stylers": [ - { - "color": "#242f3e" - } - ] - }, - { - "featureType": "administrative.locality", - "elementType": "labels.text.fill", - "stylers": [ - { - "color": "#d59563" - } - ] - }, - { - "featureType": "poi", - "elementType": "labels.text.fill", - "stylers": [ - { - "color": "#d59563" - } - ] - }, - { - "featureType": "poi.park", - "elementType": "geometry", - "stylers": [ - { - "color": "#263c3f" - } - ] - }, - { - "featureType": "poi.park", - "elementType": "labels.text.fill", - "stylers": [ - { - "color": "#6b9a76" - } - ] - }, - { - "featureType": "road", - "elementType": "geometry", - "stylers": [ - { - "color": "#38414e" - } - ] - }, - { - "featureType": "road", - "elementType": "geometry.stroke", - "stylers": [ - { - "color": "#212a37" - } - ] - }, - { - "featureType": "road", - "elementType": "labels.text.fill", - "stylers": [ - { - "color": "#9ca5b3" - } - ] - }, - { - "featureType": "road.highway", - "elementType": "geometry", - "stylers": [ - { - "color": "#746855" - } - ] - }, - { - "featureType": "road.highway", - "elementType": "geometry.stroke", - "stylers": [ - { - "color": "#1f2835" - } - ] - }, - { - "featureType": "road.highway", - "elementType": "labels.text.fill", - "stylers": [ - { - "color": "#f3d19c" - } - ] - }, - { - "featureType": "transit", - "elementType": "geometry", - "stylers": [ - { - "color": "#2f3948" - } - ] - }, - { - "featureType": "transit.station", - "elementType": "labels.text.fill", - "stylers": [ - { - "color": "#d59563" - } - ] - }, - { - "featureType": "water", - "elementType": "geometry", - "stylers": [ - { - "color": "#17263c" - } - ] - }, - { - "featureType": "water", - "elementType": "labels.text.fill", - "stylers": [ - { - "color": "#515c6d" - } - ] - }, - { - "featureType": "water", - "elementType": "labels.text.stroke", - "stylers": [ - { - "color": "#17263c" - } - ] - } -] -'''; - final LatLngBounds sydneyBounds = LatLngBounds( southwest: const LatLng(-34.022631, 150.620685), northeast: const LatLng(-33.571835, 151.325952), @@ -223,7 +59,8 @@ class MapUiBodyState extends State { bool _myTrafficEnabled = false; bool _myLocationButtonEnabled = true; late ExampleGoogleMapController _controller; - bool _nightMode = true; + bool _nightMode = false; + String _mapStyle = ''; @override void initState() { @@ -411,9 +248,12 @@ class MapUiBodyState extends State { Widget _nightModeToggler() { return TextButton( child: Text('${_nightMode ? 'disable' : 'enable'} night mode'), - onPressed: () { + onPressed: () async { + _nightMode = !_nightMode; + final String style = + _nightMode ? await _getFileData('assets/night_mode.json') : ''; setState(() { - _nightMode = !_nightMode; + _mapStyle = style; }); }, ); @@ -429,7 +269,7 @@ class MapUiBodyState extends State { cameraTargetBounds: _cameraTargetBounds, minMaxZoomPreference: _minMaxZoomPreference, mapType: _mapType, - style: _nightMode ? _nightModeStyle : '', + style: _mapStyle, rotateGesturesEnabled: _rotateGesturesEnabled, scrollGesturesEnabled: _scrollGesturesEnabled, tiltGesturesEnabled: _tiltGesturesEnabled, From 7721166a65fd60a03e93d672612a0a13ce56ff47 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 23 Feb 2024 11:49:34 -0500 Subject: [PATCH 09/16] web implementation --- .../google_maps_controller_test.dart | 63 ++++++++++++++++++- .../lib/src/convert.dart | 1 + .../lib/src/google_maps_controller.dart | 33 +++++++++- .../lib/src/google_maps_flutter_web.dart | 5 ++ 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.dart index 51c36a55a478..008f1d588497 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.dart @@ -444,6 +444,46 @@ void main() { expect(capturedOptions!.zoom, 12); expect(capturedOptions!.center, isNotNull); }); + + testWidgets('translates style option', (WidgetTester tester) async { + const String style = ''' +[{ + "featureType": "poi.park", + "elementType": "labels.text.fill", + "stylers": [{"color": "#6b9a76"}] +}]'''; + controller = createController( + mapConfiguration: const MapConfiguration(style: style)); + controller.debugSetOverrides( + createMap: (_, gmaps.MapOptions options) { + capturedOptions = options; + return map; + }); + + controller.init(); + + expect(capturedOptions, isNotNull); + expect(capturedOptions!.styles?.length, 1); + }); + + testWidgets('stores style errors for later querying', + (WidgetTester tester) async { + controller = createController( + mapConfiguration: const MapConfiguration( + style: '[[invalid style', zoomControlsEnabled: true)); + controller.debugSetOverrides( + createMap: (_, gmaps.MapOptions options) { + capturedOptions = options; + return map; + }); + + controller.init(); + + expect(controller.lastStyleError, isNotNull); + // Style failures should not prevent other options from being set. + expect(capturedOptions, isNotNull); + expect(capturedOptions!.zoomControl, true); + }); }); group('Traffic Layer', () { @@ -481,7 +521,7 @@ void main() { ..init(); }); - group('updateRawOptions', () { + group('updateMapConfiguration', () { testWidgets('can update `options`', (WidgetTester tester) async { controller.updateMapConfiguration(const MapConfiguration( mapType: MapType.satellite, @@ -505,6 +545,27 @@ void main() { expect(controller.trafficLayer, isNull); }); + + testWidgets('can update style', (WidgetTester tester) async { + const String style = ''' +[{ + "featureType": "poi.park", + "elementType": "labels.text.fill", + "stylers": [{"color": "#6b9a76"}] +}]'''; + controller + .updateMapConfiguration(const MapConfiguration(style: style)); + + expect(controller.styles.length, 1); + }); + + testWidgets('can update style', (WidgetTester tester) async { + controller.updateMapConfiguration( + const MapConfiguration(style: '[[[invalid style')); + + expect(controller.styles, isEmpty); + expect(controller.lastStyleError, isNotNull); + }); }); group('viewport getters', () { 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 8ca6a75559f4..75388e492d80 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 @@ -80,6 +80,7 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions( options.fullscreenControl = false; options.streetViewControl = false; + // See updateMapConfiguration for why this is not using configuration.style. options.styles = styles; options.mapId = configuration.cloudMapId; diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart index 494029ce02c5..d4155040d180 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart @@ -32,6 +32,7 @@ class GoogleMapController { _polylinesController = PolylinesController(stream: _streamController); _markersController = MarkersController(stream: _streamController); _tileOverlaysController = TileOverlaysController(); + _updateStylesFromConfiguration(mapConfiguration); // Register the view factory that will hold the `_div` that holds the map in the DOM. // The `_div` needs to be created outside of the ViewFactory (and cached!) so we can @@ -60,6 +61,8 @@ class GoogleMapController { // Caching this allows us to re-create the map faithfully when needed. MapConfiguration _lastMapConfiguration = const MapConfiguration(); List _lastStyles = const []; + // The last error resulting from providing a map style, if any. + String? _lastStyleError; /// Configuration accessor for the [GoogleMapsInspectorWeb]. /// @@ -279,15 +282,36 @@ class GoogleMapController { return _lastMapConfiguration; } + // TODO(stuartmorgan): Refactor so that _lastMapConfiguration.style is the + // source of truth for style info. Currently it's tracked and handled + // separately since style didn't used to be part of the configuration. + List _updateStylesFromConfiguration( + MapConfiguration update) { + if (update.style != null) { + // Provide async access to the error rather than throwing, to match the + // behavior of other platforms where there's no mechanism to return errors + // from configuration updates. + try { + _lastStyles = _mapStyles(update.style); + _lastStyleError = null; + } on MapStyleException catch (e) { + _lastStyleError = e.cause; + } + } + return _lastStyles; + } + /// Updates the map options from a [MapConfiguration]. /// /// This method converts the map into the proper [gmaps.MapOptions]. void updateMapConfiguration(MapConfiguration update) { assert(_googleMap != null, 'Cannot update options on a null map.'); + final List styles = + _updateStylesFromConfiguration(update); final MapConfiguration newConfiguration = _mergeConfigurations(update); final gmaps.MapOptions newOptions = - _configurationAndStyleToGmapsOptions(newConfiguration, _lastStyles); + _configurationAndStyleToGmapsOptions(newConfiguration, styles); _setOptions(newOptions); _setTrafficLayer(_googleMap!, newConfiguration.trafficEnabled ?? false); @@ -300,6 +324,13 @@ class GoogleMapController { _configurationAndStyleToGmapsOptions(_lastMapConfiguration, styles)); } + /// A getter for the current styles. Only for tests. + @visibleForTesting + List get styles => _lastStyles; + + /// Returns the last error from setting the map's style, if any. + String? get lastStyleError => _lastStyleError; + // Sets new [gmaps.MapOptions] on the wrapped map. // ignore: use_setters_to_change_properties void _setOptions(gmaps.MapOptions options) { diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_flutter_web.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_flutter_web.dart index 140fd3e1888d..805887f0d7f5 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_flutter_web.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_flutter_web.dart @@ -279,6 +279,11 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { return _events(mapId).whereType(); } + @override + Future getStyleError({required int mapId}) async { + return _map(mapId).lastStyleError; + } + /// Disposes of the current map. It can't be used afterwards! @override void dispose({required int mapId}) { From d4c9bfba133fd660067bd00338349f3de555e7d6 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 23 Feb 2024 12:16:48 -0500 Subject: [PATCH 10/16] Plumb through app-facing --- .../integration_test/src/maps_controller.dart | 22 ++++++++++++ .../example/lib/map_ui.dart | 34 ++++++++++--------- .../google_maps_flutter/example/pubspec.yaml | 5 ++- .../lib/src/controller.dart | 6 ++++ .../lib/src/google_map.dart | 19 +++++++++-- .../google_maps_flutter/pubspec.yaml | 5 ++- .../test/google_map_test.dart | 28 +++++++++++++++ 7 files changed, 98 insertions(+), 21 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/example/integration_test/src/maps_controller.dart b/packages/google_maps_flutter/google_maps_flutter/example/integration_test/src/maps_controller.dart index 01716232814e..addd0bc0e502 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/integration_test/src/maps_controller.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/integration_test/src/maps_controller.dart @@ -448,6 +448,28 @@ void runTests() { await mapIdCompleter.future; }, ); + + testWidgets('getStyleError reports last error', (WidgetTester tester) async { + final Key key = GlobalKey(); + final Completer controllerCompleter = + Completer(); + + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + key: key, + initialCameraPosition: kInitialCameraPosition, + style: '[[[this is an invalid style', + onMapCreated: (GoogleMapController controller) { + controllerCompleter.complete(controller); + }, + ), + )); + + final GoogleMapController controller = await controllerCompleter.future; + final String? error = await controller.getStyleError(); + expect(error, isNotNull); + }); } /// Repeatedly checks an asynchronous value against a test condition. diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/map_ui.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/map_ui.dart index 5348c1001af7..26c0b2ab720a 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/map_ui.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/map_ui.dart @@ -4,6 +4,7 @@ // ignore_for_file: public_member_api_docs +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show rootBundle; import 'package:google_maps_flutter/google_maps_flutter.dart'; @@ -59,6 +60,7 @@ class MapUiBodyState extends State { bool _myLocationButtonEnabled = true; late GoogleMapController _controller; bool _nightMode = false; + String _mapStyle = ''; @override void initState() { @@ -243,27 +245,18 @@ class MapUiBodyState extends State { return rootBundle.loadString(path); } - void _setMapStyle(String mapStyle) { - setState(() { - _nightMode = true; - _controller.setMapStyle(mapStyle); - }); - } - // Should only be called if _isMapCreated is true. Widget _nightModeToggler() { assert(_isMapCreated); return TextButton( child: Text('${_nightMode ? 'disable' : 'enable'} night mode'), - onPressed: () { - if (_nightMode) { - setState(() { - _nightMode = false; - _controller.setMapStyle(null); - }); - } else { - _getFileData('assets/night_mode.json').then(_setMapStyle); - } + onPressed: () async { + _nightMode = !_nightMode; + final String style = + _nightMode ? await _getFileData('assets/night_mode.json') : ''; + setState(() { + _mapStyle = style; + }); }, ); } @@ -278,6 +271,7 @@ class MapUiBodyState extends State { cameraTargetBounds: _cameraTargetBounds, minMaxZoomPreference: _minMaxZoomPreference, mapType: _mapType, + style: _mapStyle, rotateGesturesEnabled: _rotateGesturesEnabled, scrollGesturesEnabled: _scrollGesturesEnabled, tiltGesturesEnabled: _tiltGesturesEnabled, @@ -352,5 +346,13 @@ class MapUiBodyState extends State { _controller = controller; _isMapCreated = true; }); + // Log any style errors to the console for debugging. + if (kDebugMode) { + _controller.getStyleError().then((String? error) { + if (error != null) { + debugPrint(error); + } + }); + } } } 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 7890b777dd0a..1d452f47299f 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml @@ -37,4 +37,7 @@ flutter: # FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. # See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../../google_maps_flutter/google_maps_flutter_platform_interface}} + google_maps_flutter_android: {path: ../../../google_maps_flutter/google_maps_flutter_android} + google_maps_flutter_ios: {path: ../../../google_maps_flutter/google_maps_flutter_ios} + google_maps_flutter_platform_interface: {path: ../../../google_maps_flutter/google_maps_flutter_platform_interface} + google_maps_flutter_web: {path: ../../../google_maps_flutter/google_maps_flutter_web} diff --git a/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart b/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart index 095d15867acc..393288a6165f 100644 --- a/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart +++ b/packages/google_maps_flutter/google_maps_flutter/lib/src/controller.dart @@ -190,11 +190,17 @@ class GoogleMapController { /// Also, refer [iOS](https://developers.google.com/maps/documentation/ios-sdk/style-reference) /// and [Android](https://developers.google.com/maps/documentation/android-sdk/style-reference) /// style reference for more information regarding the supported styles. + @Deprecated('Use GoogleMap.style instead.') Future setMapStyle(String? mapStyle) { return GoogleMapsFlutterPlatform.instance .setMapStyle(mapStyle, mapId: mapId); } + /// Returns the last style error, if any. + Future getStyleError() { + return GoogleMapsFlutterPlatform.instance.getStyleError(mapId: mapId); + } + /// Return [LatLngBounds] defining the region that is visible in a map. Future getVisibleRegion() { return GoogleMapsFlutterPlatform.instance.getVisibleRegion(mapId: mapId); 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 dd55104cb3be..c50ffccfa634 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 @@ -91,7 +91,7 @@ class GoogleMap extends StatefulWidget { const GoogleMap({ super.key, required this.initialCameraPosition, - this.initialMapStyle, + this.style, this.onMapCreated, this.gestureRecognizers = const >{}, this.webGestureHandling, @@ -137,8 +137,18 @@ class GoogleMap extends StatefulWidget { /// The initial position of the map's camera. final CameraPosition initialCameraPosition; - /// The initial map style used when the controller is created. - final String? initialMapStyle; + /// The style for the map. + /// + /// Set to null to clear any previous custom styling. + /// + /// If problems were detected with the [mapStyle], including un-parsable + /// styling JSON, unrecognized feature type, unrecognized element type, or + /// invalid styler keys, the style is left unchanged, and the error can be + /// retrieved with [GoogleMapController.getStyleError]. + /// + /// The style string can be generated using the + /// [map style tool](https://mapstyle.withgoogle.com/). + final String? style; /// True if the map should show a compass when rotated. final bool compassEnabled; @@ -560,5 +570,8 @@ MapConfiguration _configurationFromMapWidget(GoogleMap map) { trafficEnabled: map.trafficEnabled, buildingsEnabled: map.buildingsEnabled, cloudMapId: map.cloudMapId, + // 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 a504638e2a05..51bd43720452 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -44,4 +44,7 @@ false_secrets: # FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. # See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface}} + google_maps_flutter_android: {path: ../../google_maps_flutter/google_maps_flutter_android} + google_maps_flutter_ios: {path: ../../google_maps_flutter/google_maps_flutter_ios} + google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface} + google_maps_flutter_web: {path: ../../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 7005a8d3ab60..9276a7dbda30 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 @@ -551,4 +551,32 @@ void main() { expect(map.mapConfiguration.buildingsEnabled, true); }); + + testWidgets('Can update style', (WidgetTester tester) async { + const String initialStyle = '[]'; + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), + style: initialStyle, + ), + ), + ); + + final PlatformMapStateRecorder map = platform.lastCreatedMap; + + expect(map.mapConfiguration.style, initialStyle); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)), + ), + ), + ); + + expect(map.mapConfiguration.style, ''); + }); } From dd188d1c1c5c5cb84d4fcc000ac6f496b7354750 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 23 Feb 2024 13:00:04 -0500 Subject: [PATCH 11/16] Fix test --- .../platform_interface/google_maps_flutter_platform_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5e0d7921fb8f..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 @@ -89,7 +89,7 @@ void main() { () async { final GoogleMapsFlutterPlatform platform = BuildViewGoogleMapsFlutterPlatform(); - expect(await platform.getStyleError(), null); + expect(await platform.getStyleError(mapId: 0), null); }, ); }); From 2e8a190de3df18e6cf2a19a8651aa9a333193b67 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 23 Feb 2024 13:03:47 -0500 Subject: [PATCH 12/16] version bump --- .../google_maps_flutter/google_maps_flutter/CHANGELOG.md | 7 ++++++- .../google_maps_flutter/google_maps_flutter/pubspec.yaml | 2 +- .../google_maps_flutter_android/CHANGELOG.md | 4 +++- .../google_maps_flutter_android/pubspec.yaml | 2 +- .../google_maps_flutter_ios/CHANGELOG.md | 5 +++++ .../google_maps_flutter_ios/pubspec.yaml | 2 +- .../google_maps_flutter_platform_interface/CHANGELOG.md | 6 +++++- .../google_maps_flutter_platform_interface/pubspec.yaml | 2 +- .../google_maps_flutter_web/CHANGELOG.md | 4 +++- .../google_maps_flutter_web/pubspec.yaml | 2 +- 10 files changed, 27 insertions(+), 9 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md index 095e04709027..cf49bb9c4d3d 100644 --- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md @@ -1,5 +1,10 @@ -## NEXT +## 2.6.0 +* Adds `style` to the GoogleMap widget constructor. This allows setting the map + style during creation, avoiding the possibility of the default style being + displayed briefly. +* Deprecates `GoogleMapController.setMapStyle` in favor of setting the style via + the new widget `style` parameter. * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. ## 2.5.3 diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 51bd43720452..40325e8fa744 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.5.3 +version: 2.6.0 environment: sdk: ^3.1.0 diff --git a/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md index ba2011f39be2..a099bb5ef424 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md @@ -1,5 +1,7 @@ -## NEXT +## 2.7.0 +* Adds support for `MapConfiguration.style`. +* Adds support for `getStyleError`. * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. * Updates compileSdk version to 34. diff --git a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml index b48aed86b9a3..5a6955253014 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_android description: Android implementation of the google_maps_flutter plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 2.6.2 +version: 2.7.0 environment: sdk: ^3.1.0 diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md index 4eae3cfc1f0f..6778f3b8e1ee 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.5.0 + +* Adds support for `MapConfiguration.style`. +* Adds support for `getStyleError`. + ## 2.4.2 * Fixes a bug in "takeSnapshot" function that incorrectly returns a blank image on iOS 17. diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml index 09b028bb9509..a029c3965d4b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_ios description: iOS implementation of the google_maps_flutter plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 2.4.2 +version: 2.5.0 environment: sdk: ^3.2.3 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/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_web/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md index a8de9d0147e7..adabfee22779 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,7 @@ -## NEXT +## 0.5.5 +* Adds support for `MapConfiguration.style`. +* Adds support for `getStyleError`. * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. ## 0.5.4+3 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 3562c8e30575..1776e364ef0a 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.4+3 +version: 0.5.5 environment: sdk: ">=3.1.0 <4.0.0" From 36a6f84456af5888df2ae8346ddf60897e7ed3a3 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 23 Feb 2024 13:04:10 -0500 Subject: [PATCH 13/16] Autoformat --- .../plugins/googlemaps/GoogleMapBuilder.java | 2 - .../googlemaps/GoogleMapController.java | 38 ++++++++++--------- .../googlemaps/GoogleMapOptionsSink.java | 1 - .../ios/Classes/GoogleMapController.m | 2 +- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java index 4f167b583809..dfbaf02b9d4a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java @@ -6,9 +6,7 @@ import android.content.Context; import android.graphics.Rect; - import androidx.annotation.Nullable; - import com.google.android.gms.maps.GoogleMapOptions; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLngBounds; diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index 4aba93940e68..b4102471c4b2 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -466,23 +466,23 @@ public void onSnapshotReady(Bitmap bitmap) { break; } case "map#setStyle": - { - Object arg = call.arguments; - final String style = arg instanceof String ? (String) arg : null; - final boolean mapStyleSet = updateMapStyle(style); - ArrayList mapStyleResult = new ArrayList<>(2); - mapStyleResult.add(mapStyleSet); - if (!mapStyleSet) { - mapStyleResult.add(lastStyleError); - } - result.success(mapStyleResult); - break; - } + { + Object arg = call.arguments; + final String style = arg instanceof String ? (String) arg : null; + final boolean mapStyleSet = updateMapStyle(style); + ArrayList mapStyleResult = new ArrayList<>(2); + mapStyleResult.add(mapStyleSet); + if (!mapStyleSet) { + mapStyleResult.add(lastStyleError); + } + result.success(mapStyleResult); + break; + } case "map#getStyleError": - { - result.success(lastStyleError); - break; - } + { + result.success(lastStyleError); + break; + } case "tileOverlays#update": { List> tileOverlaysToAdd = call.argument("tileOverlaysToAdd"); @@ -941,9 +941,11 @@ public void setMapStyle(@Nullable String style) { private boolean updateMapStyle(String style) { // Dart passes an empty string to indicate that the style should be cleared. - final MapStyleOptions mapStyleOptions = style == null || style.isEmpty() ? null : new MapStyleOptions(style); + final MapStyleOptions mapStyleOptions = + style == null || style.isEmpty() ? null : new MapStyleOptions(style); final boolean set = Objects.requireNonNull(googleMap).setMapStyle(mapStyleOptions); - lastStyleError = set ? null : "Unable to set the map style. Please check console logs for errors."; + lastStyleError = + set ? null : "Unable to set the map style. Please check console logs for errors."; return set; } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java index 34cfc1f7aeb1..95c550c92fd8 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java @@ -5,7 +5,6 @@ package io.flutter.plugins.googlemaps; import androidx.annotation.Nullable; - import com.google.android.gms.maps.model.LatLngBounds; import java.util.List; import java.util.Map; diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m index b619527fa95c..0b9b09b7748c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m @@ -665,7 +665,7 @@ - (void)interpretMapOptions:(NSDictionary *)data { if (myLocationButtonEnabled && myLocationButtonEnabled != (id)[NSNull null]) { [self setMyLocationButtonEnabled:[myLocationButtonEnabled boolValue]]; } - NSString* style = data[@"style"]; + NSString *style = data[@"style"]; if (style) { self.styleError = [self setMapStyle:style]; } From 1de84dbe578770227590944e8bc33bb35fc0589f Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Fri, 23 Feb 2024 17:33:38 -0800 Subject: [PATCH 14/16] Use pumpMap for getStyleError test. --- .../example/integration_test/src/maps_controller.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/example/integration_test/src/maps_controller.dart b/packages/google_maps_flutter/google_maps_flutter/example/integration_test/src/maps_controller.dart index addd0bc0e502..3d99369e33be 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/integration_test/src/maps_controller.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/integration_test/src/maps_controller.dart @@ -454,9 +454,9 @@ void runTests() { final Completer controllerCompleter = Completer(); - await tester.pumpWidget(Directionality( - textDirection: TextDirection.ltr, - child: GoogleMap( + await pumpMap( + tester, + GoogleMap( key: key, initialCameraPosition: kInitialCameraPosition, style: '[[[this is an invalid style', @@ -464,7 +464,7 @@ void runTests() { controllerCompleter.complete(controller); }, ), - )); + ); final GoogleMapController controller = await controllerCompleter.future; final String? error = await controller.getStyleError(); From 953fb8e2a3507455d11ffb82dfc14997fa013336 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 26 Feb 2024 07:46:26 -0500 Subject: [PATCH 15/16] Unwind PI overrides --- .../google_maps_flutter/example/pubspec.yaml | 3 +-- .../google_maps_flutter/google_maps_flutter/pubspec.yaml | 3 +-- .../google_maps_flutter_android/example/pubspec.yaml | 7 +------ .../google_maps_flutter_android/pubspec.yaml | 7 +------ .../google_maps_flutter_ios/example/ios12/pubspec.yaml | 7 +------ .../google_maps_flutter_ios/example/ios13/pubspec.yaml | 7 +------ .../google_maps_flutter_ios/example/ios14/pubspec.yaml | 7 +------ .../example/shared/maps_example_dart/pubspec.yaml | 7 +------ .../google_maps_flutter_ios/pubspec.yaml | 7 +------ .../google_maps_flutter_web/example/pubspec.yaml | 8 +------- .../google_maps_flutter_web/pubspec.yaml | 7 +------ 11 files changed, 11 insertions(+), 59 deletions(-) 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 1d452f47299f..f1413fe5672d 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: # the parent directory to use the current plugin's version. path: ../ google_maps_flutter_android: ^2.5.0 - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 dev_dependencies: build_runner: ^2.1.10 @@ -39,5 +39,4 @@ flutter: dependency_overrides: google_maps_flutter_android: {path: ../../../google_maps_flutter/google_maps_flutter_android} google_maps_flutter_ios: {path: ../../../google_maps_flutter/google_maps_flutter_ios} - google_maps_flutter_platform_interface: {path: ../../../google_maps_flutter/google_maps_flutter_platform_interface} google_maps_flutter_web: {path: ../../../google_maps_flutter/google_maps_flutter_web} diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 40325e8fa744..4132cc9166e6 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: sdk: flutter google_maps_flutter_android: ^2.5.0 google_maps_flutter_ios: ^2.3.0 - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 google_maps_flutter_web: ^0.5.2 dev_dependencies: @@ -46,5 +46,4 @@ false_secrets: dependency_overrides: google_maps_flutter_android: {path: ../../google_maps_flutter/google_maps_flutter_android} google_maps_flutter_ios: {path: ../../google_maps_flutter/google_maps_flutter_ios} - google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface} google_maps_flutter_web: {path: ../../google_maps_flutter/google_maps_flutter_web} diff --git a/packages/google_maps_flutter/google_maps_flutter_android/example/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_android/example/pubspec.yaml index ef32aa1c8da6..533ca53c2914 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/example/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_android/example/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: # The example app is bundled with the plugin so we use a path dependency on # the parent directory to use the current plugin's version. path: ../ - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 dev_dependencies: build_runner: ^2.1.10 @@ -33,8 +33,3 @@ flutter: uses-material-design: true assets: - assets/ - -# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. -# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml index 5a6955253014..1f2a3be877c1 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 stream_transform: ^2.0.0 dev_dependencies: @@ -34,8 +34,3 @@ topics: - google-maps - google-maps-flutter - map - -# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. -# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/pubspec.yaml index 846b5cf22208..a0b172a65e1c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: # The example app is bundled with the plugin so we use a path dependency on # the parent directory to use the current plugin's version. path: ../../ - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 maps_example_dart: path: ../shared/maps_example_dart/ @@ -32,8 +32,3 @@ flutter: uses-material-design: true assets: - assets/ - -# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. -# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/pubspec.yaml index 846b5cf22208..a0b172a65e1c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: # The example app is bundled with the plugin so we use a path dependency on # the parent directory to use the current plugin's version. path: ../../ - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 maps_example_dart: path: ../shared/maps_example_dart/ @@ -32,8 +32,3 @@ flutter: uses-material-design: true assets: - assets/ - -# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. -# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/pubspec.yaml index 846b5cf22208..a0b172a65e1c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: # The example app is bundled with the plugin so we use a path dependency on # the parent directory to use the current plugin's version. path: ../../ - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 maps_example_dart: path: ../shared/maps_example_dart/ @@ -32,8 +32,3 @@ flutter: uses-material-design: true assets: - assets/ - -# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. -# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/pubspec.yaml index 6ccbe4fe2a08..77063ec00061 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: # The example app is bundled with the plugin so we use a path dependency on # the parent directory to use the current plugin's version. path: ../../../ - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 dev_dependencies: flutter_test: @@ -27,8 +27,3 @@ dev_dependencies: flutter: uses-material-design: true - -# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. -# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../../../../google_maps_flutter/google_maps_flutter_platform_interface}} diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml index a029c3965d4b..a90927475205 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml @@ -19,7 +19,7 @@ flutter: dependencies: flutter: sdk: flutter - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 stream_transform: ^2.0.0 dev_dependencies: @@ -32,8 +32,3 @@ topics: - google-maps - google-maps-flutter - map - -# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. -# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface}} 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 d3b66d667ef1..b3c5062de3e7 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 @@ -9,7 +9,7 @@ environment: dependencies: flutter: sdk: flutter - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 google_maps_flutter_web: path: ../ @@ -24,15 +24,9 @@ dev_dependencies: sdk: flutter mockito: 5.4.4 - -# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. -# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#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_platform_interface: - path: ../../../google_maps_flutter/google_maps_flutter_platform_interface google_maps_flutter_web: path: ../ 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 1776e364ef0a..1f3c95408b73 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: flutter_web_plugins: sdk: flutter google_maps: ^6.1.0 - google_maps_flutter_platform_interface: ^2.4.0 + google_maps_flutter_platform_interface: ^2.5.0 sanitize_html: ^2.0.0 stream_transform: ^2.0.0 @@ -39,8 +39,3 @@ 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/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - {google_maps_flutter_platform_interface: {path: ../../google_maps_flutter/google_maps_flutter_platform_interface}} From db1c58ec633b703d8c60e90943dc0b57a1ce6c6a Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 28 Feb 2024 10:02:08 -0500 Subject: [PATCH 16/16] Remove remaining overrides; update actual constraints --- .../google_maps_flutter/CHANGELOG.md | 2 +- .../google_maps_flutter/example/pubspec.yaml | 7 ------- .../google_maps_flutter/pubspec.yaml | 17 +++++------------ 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md index cf49bb9c4d3d..50ca4a9e6894 100644 --- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md @@ -5,7 +5,7 @@ displayed briefly. * Deprecates `GoogleMapController.setMapStyle` in favor of setting the style via the new widget `style` parameter. -* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. +* Updates minimum supported SDK version to Flutter 3.19. ## 2.5.3 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 f1413fe5672d..ba306fd8bd9e 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml @@ -33,10 +33,3 @@ flutter: uses-material-design: true assets: - assets/ - -# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. -# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - google_maps_flutter_android: {path: ../../../google_maps_flutter/google_maps_flutter_android} - google_maps_flutter_ios: {path: ../../../google_maps_flutter/google_maps_flutter_ios} - google_maps_flutter_web: {path: ../../../google_maps_flutter/google_maps_flutter_web} diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 4132cc9166e6..598ab6f7aeb6 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -5,8 +5,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 2.6.0 environment: - sdk: ^3.1.0 - flutter: ">=3.13.0" + sdk: ^3.3.0 + flutter: ">=3.19.0" flutter: plugin: @@ -21,10 +21,10 @@ flutter: dependencies: flutter: sdk: flutter - google_maps_flutter_android: ^2.5.0 - google_maps_flutter_ios: ^2.3.0 + google_maps_flutter_android: ^2.7.0 + google_maps_flutter_ios: ^2.5.0 google_maps_flutter_platform_interface: ^2.5.0 - google_maps_flutter_web: ^0.5.2 + google_maps_flutter_web: ^0.5.6 dev_dependencies: flutter_test: @@ -40,10 +40,3 @@ 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/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins -dependency_overrides: - google_maps_flutter_android: {path: ../../google_maps_flutter/google_maps_flutter_android} - google_maps_flutter_ios: {path: ../../google_maps_flutter/google_maps_flutter_ios} - google_maps_flutter_web: {path: ../../google_maps_flutter/google_maps_flutter_web}