From a1c4c0ce0c36774577c67328e4930ed8ca1fb99c Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 24 May 2022 11:13:25 -0400 Subject: [PATCH 01/15] Temp pubspec overrides --- .../google_maps_flutter/google_maps_flutter/pubspec.yaml | 6 ++++++ .../google_maps_flutter_web/pubspec.yaml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 831f3ccd2963..dbc7b7f7a5ce 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -30,3 +30,9 @@ dev_dependencies: pedantic: ^1.10.0 plugin_platform_interface: ^2.0.0 stream_transform: ^2.0.0 + + +# FOR TESTING ONLY. DO NOT MERGE. +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/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml index b46f7561e78d..2db1d57b6556 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -33,3 +33,9 @@ dev_dependencies: # The example deliberately includes limited-use secrets. false_secrets: - /example/web/index.html + + +# FOR TESTING ONLY. DO NOT MERGE. +dependency_overrides: + google_maps_flutter_platform_interface: + path: ../../google_maps_flutter/google_maps_flutter_platform_interface From 00af9e67536f97bf1d9401897e593b51de6c1123 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 24 May 2022 12:06:28 -0400 Subject: [PATCH 02/15] Add new type and methods to platform interface and default impl --- .../method_channel_google_maps_flutter.dart | 85 ++++-- .../google_maps_flutter_platform.dart | 51 +++- .../lib/src/types/bitmap.dart | 6 +- .../lib/src/types/map_configuration.dart | 227 ++++++++++++++ .../lib/src/types/map_objects.dart | 31 ++ .../src/types/map_widget_configuration.dart | 32 ++ .../lib/src/types/types.dart | 3 +- .../map_configuration_serialization.dart | 62 ++++ .../google_maps_flutter_platform_test.dart | 20 ++ .../test/types/map_configuration_test.dart | 285 ++++++++++++++++++ .../map_configuration_serialization_test.dart | 75 +++++ 11 files changed, 847 insertions(+), 30 deletions(-) create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_configuration.dart create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_objects.dart create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_widget_configuration.dart create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/map_configuration_serialization.dart create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/map_configuration_test.dart create mode 100644 packages/google_maps_flutter/google_maps_flutter_platform_interface/test/utils/map_configuration_serialization_test.dart diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index 365da757e435..4994099d3a5e 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -11,9 +11,12 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/map_objects.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/map_widget_configuration.dart'; import 'package:stream_transform/stream_transform.dart'; import '../types/tile_overlay_updates.dart'; +import '../types/utils/map_configuration_serialization.dart'; /// Error thrown when an unknown map ID is provided to a method channel API. class UnknownMapIDError extends Error { @@ -482,28 +485,22 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { /// Defaults to false. bool useAndroidViewSurface = false; - @override - Widget buildViewWithTextDirection( + Widget _buildView( int creationId, PlatformViewCreatedCallback onPlatformViewCreated, { - required CameraPosition initialCameraPosition, - required TextDirection textDirection, - Set markers = const {}, - Set polygons = const {}, - Set polylines = const {}, - Set circles = const {}, - Set tileOverlays = const {}, - Set>? gestureRecognizers, + required MapWidgetConfiguration widgetConfiguration, + MapObjects mapObjects = const MapObjects(), Map mapOptions = const {}, }) { final Map creationParams = { - 'initialCameraPosition': initialCameraPosition.toMap(), + 'initialCameraPosition': + widgetConfiguration.initialCameraPosition.toMap(), 'options': mapOptions, - 'markersToAdd': serializeMarkerSet(markers), - 'polygonsToAdd': serializePolygonSet(polygons), - 'polylinesToAdd': serializePolylineSet(polylines), - 'circlesToAdd': serializeCircleSet(circles), - 'tileOverlaysToAdd': serializeTileOverlaySet(tileOverlays), + 'markersToAdd': serializeMarkerSet(mapObjects.markers), + 'polygonsToAdd': serializePolygonSet(mapObjects.polygons), + 'polylinesToAdd': serializePolylineSet(mapObjects.polylines), + 'circlesToAdd': serializeCircleSet(mapObjects.circles), + 'tileOverlaysToAdd': serializeTileOverlaySet(mapObjects.tileOverlays), }; if (defaultTargetPlatform == TargetPlatform.android) { @@ -516,8 +513,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { ) { return AndroidViewSurface( controller: controller as AndroidViewController, - gestureRecognizers: gestureRecognizers ?? - const >{}, + gestureRecognizers: widgetConfiguration.gestureRecognizers, hitTestBehavior: PlatformViewHitTestBehavior.opaque, ); }, @@ -526,7 +522,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { PlatformViewsService.initSurfaceAndroidView( id: params.id, viewType: 'plugins.flutter.io/google_maps', - layoutDirection: textDirection, + layoutDirection: widgetConfiguration.textDirection, creationParams: creationParams, creationParamsCodec: const StandardMessageCodec(), onFocus: () => params.onFocusChanged(true), @@ -546,7 +542,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { return AndroidView( viewType: 'plugins.flutter.io/google_maps', onPlatformViewCreated: onPlatformViewCreated, - gestureRecognizers: gestureRecognizers, + gestureRecognizers: widgetConfiguration.gestureRecognizers, creationParams: creationParams, creationParamsCodec: const StandardMessageCodec(), ); @@ -555,7 +551,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { return UiKitView( viewType: 'plugins.flutter.io/google_maps', onPlatformViewCreated: onPlatformViewCreated, - gestureRecognizers: gestureRecognizers, + gestureRecognizers: widgetConfiguration.gestureRecognizers, creationParams: creationParams, creationParamsCodec: const StandardMessageCodec(), ); @@ -565,6 +561,53 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { '$defaultTargetPlatform is not yet supported by the maps plugin'); } + @override + Widget buildViewWithConfiguration( + int creationId, + PlatformViewCreatedCallback onPlatformViewCreated, { + required MapWidgetConfiguration widgetConfiguration, + MapConfiguration mapConfiguration = const MapConfiguration(), + MapObjects mapObjects = const MapObjects(), + }) { + return _buildView( + creationId, + onPlatformViewCreated, + widgetConfiguration: widgetConfiguration, + mapObjects: mapObjects, + mapOptions: jsonForMapConfiguration(mapConfiguration), + ); + } + + @override + Widget buildViewWithTextDirection( + int creationId, + PlatformViewCreatedCallback onPlatformViewCreated, { + required CameraPosition initialCameraPosition, + required TextDirection textDirection, + Set markers = const {}, + Set polygons = const {}, + Set polylines = const {}, + Set circles = const {}, + Set tileOverlays = const {}, + Set>? gestureRecognizers, + Map mapOptions = const {}, + }) { + return _buildView( + creationId, + onPlatformViewCreated, + widgetConfiguration: MapWidgetConfiguration( + initialCameraPosition: initialCameraPosition, + textDirection: textDirection), + mapObjects: MapObjects( + markers: markers, + polygons: polygons, + polylines: polylines, + circles: circles, + tileOverlays: tileOverlays), + mapOptions: mapOptions, + ); + } + @override Widget buildView( int creationId, 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 6386ed2523f2..17ade5d09a61 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 @@ -11,6 +11,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/map_objects.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/map_widget_configuration.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/utils/map_configuration_serialization.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; /// The interface that platform-specific implementations of `google_maps_flutter` must extend. @@ -48,7 +51,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { throw UnimplementedError('init() has not been implemented.'); } - /// Updates configuration options of the map user interface. + /// Updates configuration options of the map user interface - deprecated, use + /// updateMapConfiguration instead. /// /// Change listeners are notified once the update has been made on the /// platform side. @@ -61,6 +65,20 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { throw UnimplementedError('updateMapOptions() has not been implemented.'); } + /// Updates configuration options of the map user interface. + /// + /// Change listeners are notified once the update has been made on the + /// platform side. + /// + /// The returned [Future] completes after listeners have been notified. + Future updateMapConfiguration( + MapConfiguration configuration, { + required int mapId, + }) { + return updateMapOptions(jsonForMapConfiguration(configuration), + mapId: mapId); + } + /// Updates marker configuration. /// /// Change listeners are notified once the update has been made on the @@ -346,7 +364,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { throw UnimplementedError('dispose() has not been implemented.'); } - /// Returns a widget displaying the map view. + /// Returns a widget displaying the map view - deprecated, use + /// [buildViewWithConfiguration] instead. Widget buildView( int creationId, PlatformViewCreatedCallback onPlatformViewCreated, { @@ -365,7 +384,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { throw UnimplementedError('buildView() has not been implemented.'); } - /// Returns a widget displaying the map view. + /// Returns a widget displaying the map view - deprecated, use + /// [buildViewWithConfiguration] instead. /// /// This method is similar to [buildView], but contains a parameter for /// platforms that require a text direction. @@ -379,12 +399,12 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { PlatformViewCreatedCallback onPlatformViewCreated, { required CameraPosition initialCameraPosition, required TextDirection textDirection, + Set>? gestureRecognizers, Set markers = const {}, Set polygons = const {}, Set polylines = const {}, Set circles = const {}, Set tileOverlays = const {}, - Set>? gestureRecognizers, Map mapOptions = const {}, }) { return buildView( @@ -400,4 +420,27 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface { mapOptions: mapOptions, ); } + + /// Returns a widget displaying the map view. + Widget buildViewWithConfiguration( + int creationId, + PlatformViewCreatedCallback onPlatformViewCreated, { + required MapWidgetConfiguration widgetConfiguration, + MapConfiguration mapConfiguration = const MapConfiguration(), + MapObjects mapObjects = const MapObjects(), + }) { + return buildViewWithTextDirection( + creationId, + onPlatformViewCreated, + initialCameraPosition: widgetConfiguration.initialCameraPosition, + textDirection: widgetConfiguration.textDirection, + markers: mapObjects.markers, + polygons: mapObjects.polygons, + polylines: mapObjects.polylines, + circles: mapObjects.circles, + tileOverlays: mapObjects.tileOverlays, + gestureRecognizers: widgetConfiguration.gestureRecognizers, + mapOptions: jsonForMapConfiguration(mapConfiguration), + ); + } } diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart index c43baf42db45..0ccc3e624abe 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart @@ -18,10 +18,8 @@ class BitmapDescriptor { const BitmapDescriptor._(this._json); /// The inverse of .toJson. - // This is needed in Web to re-hydrate BitmapDescriptors that have been - // transformed to JSON for transport. - // TODO(stuartmorgan): Clean this up. See - // https://github.com/flutter/flutter/issues/70330 + // TODO(stuartmorgan): Remove this in the next breaking change. + @Deprecated('No longer supported') BitmapDescriptor.fromJson(Object json) : _json = json { assert(_json is List); final List jsonList = json as List; 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 new file mode 100644 index 000000000000..ce0519c9783a --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_configuration.dart @@ -0,0 +1,227 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'ui.dart'; + +/// Configuration options for the GoogleMaps user interface. +@immutable +class MapConfiguration { + /// Creates a new configuration instance with the given options. + /// + /// Any options that aren't passed will be null, which allows this to serve + /// as either a full configuration selection, or an update to an existing + /// configuration where only non-null values are updated. + const MapConfiguration({ + this.compassEnabled, + this.mapToolbarEnabled, + this.cameraTargetBounds, + this.mapType, + this.minMaxZoomPreference, + this.rotateGesturesEnabled, + this.scrollGesturesEnabled, + this.tiltGesturesEnabled, + this.trackCameraPosition, + this.zoomControlsEnabled, + this.zoomGesturesEnabled, + this.liteModeEnabled, + this.myLocationEnabled, + this.myLocationButtonEnabled, + this.padding, + this.indoorViewEnabled, + this.trafficEnabled, + this.buildingsEnabled, + }); + + /// True if the compass UI should be shown. + final bool? compassEnabled; + + /// True if the map toolbar should be shown. + final bool? mapToolbarEnabled; + + /// The bounds to display. + final CameraTargetBounds? cameraTargetBounds; + + /// The type of the map. + final MapType? mapType; + + /// The prefered zoom range. + final MinMaxZoomPreference? minMaxZoomPreference; + + /// True if rotate gestures should be enabled. + final bool? rotateGesturesEnabled; + + /// True if scroll gestures should be enabled. + final bool? scrollGesturesEnabled; + + /// True if tilt gestures should be enabled. + final bool? tiltGesturesEnabled; + + /// True if camera position changes should trigger notifications. + final bool? trackCameraPosition; + + /// True if zoom controls should be displayed. + final bool? zoomControlsEnabled; + + /// True if zoom gestures should be enabled. + final bool? zoomGesturesEnabled; + + /// True if the map should use Lite Mode, showing a limited-interactivity + /// bitmap, on supported platforms. + final bool? liteModeEnabled; + + /// True if the current location should be tracked and displayed. + final bool? myLocationEnabled; + + /// True if the control to jump to the current location should be displayed. + final bool? myLocationButtonEnabled; + + /// The padding for the map display. + final EdgeInsets? padding; + + /// True if indoor map views should be enabled. + final bool? indoorViewEnabled; + + /// True if the traffic overlay should be enabled. + final bool? trafficEnabled; + + /// True if 3D building display should be enabled. + final bool? buildingsEnabled; + + /// Returns a new options object containing only the values of this instance + /// that are different from [other]. + MapConfiguration diffFrom(MapConfiguration other) { + return MapConfiguration( + compassEnabled: + compassEnabled != other.compassEnabled ? compassEnabled : null, + mapToolbarEnabled: mapToolbarEnabled != other.mapToolbarEnabled + ? mapToolbarEnabled + : null, + cameraTargetBounds: cameraTargetBounds != other.cameraTargetBounds + ? cameraTargetBounds + : null, + mapType: mapType != other.mapType ? mapType : null, + minMaxZoomPreference: minMaxZoomPreference != other.minMaxZoomPreference + ? minMaxZoomPreference + : null, + rotateGesturesEnabled: + rotateGesturesEnabled != other.rotateGesturesEnabled + ? rotateGesturesEnabled + : null, + scrollGesturesEnabled: + scrollGesturesEnabled != other.scrollGesturesEnabled + ? scrollGesturesEnabled + : null, + tiltGesturesEnabled: tiltGesturesEnabled != other.tiltGesturesEnabled + ? tiltGesturesEnabled + : null, + trackCameraPosition: trackCameraPosition != other.trackCameraPosition + ? trackCameraPosition + : null, + zoomControlsEnabled: zoomControlsEnabled != other.zoomControlsEnabled + ? zoomControlsEnabled + : null, + zoomGesturesEnabled: zoomGesturesEnabled != other.zoomGesturesEnabled + ? zoomGesturesEnabled + : null, + liteModeEnabled: + liteModeEnabled != other.liteModeEnabled ? liteModeEnabled : null, + myLocationEnabled: myLocationEnabled != other.myLocationEnabled + ? myLocationEnabled + : null, + myLocationButtonEnabled: + myLocationButtonEnabled != other.myLocationButtonEnabled + ? myLocationButtonEnabled + : null, + padding: padding != other.padding ? padding : null, + indoorViewEnabled: indoorViewEnabled != other.indoorViewEnabled + ? indoorViewEnabled + : null, + trafficEnabled: + trafficEnabled != other.trafficEnabled ? trafficEnabled : null, + buildingsEnabled: + buildingsEnabled != other.buildingsEnabled ? buildingsEnabled : null, + ); + } + + /// Returns a copy of this instance with any non-null settings form [diff] + /// replacing the previous values. + MapConfiguration applyDiff(MapConfiguration diff) { + return MapConfiguration( + compassEnabled: diff.compassEnabled ?? compassEnabled, + mapToolbarEnabled: diff.mapToolbarEnabled ?? mapToolbarEnabled, + cameraTargetBounds: diff.cameraTargetBounds ?? cameraTargetBounds, + mapType: diff.mapType ?? mapType, + minMaxZoomPreference: diff.minMaxZoomPreference ?? minMaxZoomPreference, + rotateGesturesEnabled: + diff.rotateGesturesEnabled ?? rotateGesturesEnabled, + scrollGesturesEnabled: + diff.scrollGesturesEnabled ?? scrollGesturesEnabled, + tiltGesturesEnabled: diff.tiltGesturesEnabled ?? tiltGesturesEnabled, + trackCameraPosition: diff.trackCameraPosition ?? trackCameraPosition, + zoomControlsEnabled: diff.zoomControlsEnabled ?? zoomControlsEnabled, + zoomGesturesEnabled: diff.zoomGesturesEnabled ?? zoomGesturesEnabled, + liteModeEnabled: diff.liteModeEnabled ?? liteModeEnabled, + myLocationEnabled: diff.myLocationEnabled ?? myLocationEnabled, + myLocationButtonEnabled: + diff.myLocationButtonEnabled ?? myLocationButtonEnabled, + padding: diff.padding ?? padding, + indoorViewEnabled: diff.indoorViewEnabled ?? indoorViewEnabled, + trafficEnabled: diff.trafficEnabled ?? trafficEnabled, + buildingsEnabled: diff.buildingsEnabled ?? buildingsEnabled, + ); + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + if (other.runtimeType != runtimeType) { + return false; + } + return other is MapConfiguration && + compassEnabled == other.compassEnabled && + mapToolbarEnabled == other.mapToolbarEnabled && + cameraTargetBounds == other.cameraTargetBounds && + mapType == other.mapType && + minMaxZoomPreference == other.minMaxZoomPreference && + rotateGesturesEnabled == other.rotateGesturesEnabled && + scrollGesturesEnabled == other.scrollGesturesEnabled && + tiltGesturesEnabled == other.tiltGesturesEnabled && + trackCameraPosition == other.trackCameraPosition && + zoomControlsEnabled == other.zoomControlsEnabled && + zoomGesturesEnabled == other.zoomGesturesEnabled && + liteModeEnabled == other.liteModeEnabled && + myLocationEnabled == other.myLocationEnabled && + myLocationButtonEnabled == other.myLocationButtonEnabled && + padding == other.padding && + indoorViewEnabled == other.indoorViewEnabled && + trafficEnabled == other.trafficEnabled && + buildingsEnabled == other.buildingsEnabled; + } + + @override + int get hashCode => Object.hash( + compassEnabled, + mapToolbarEnabled, + cameraTargetBounds, + mapType, + minMaxZoomPreference, + rotateGesturesEnabled, + scrollGesturesEnabled, + tiltGesturesEnabled, + trackCameraPosition, + zoomControlsEnabled, + zoomGesturesEnabled, + liteModeEnabled, + myLocationEnabled, + myLocationButtonEnabled, + padding, + indoorViewEnabled, + trafficEnabled, + buildingsEnabled, + ); +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_objects.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_objects.dart new file mode 100644 index 000000000000..56f80e8312dd --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_objects.dart @@ -0,0 +1,31 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// ignore_for_file: public_member_api_docs + +import 'package:flutter/foundation.dart'; + +import 'types.dart'; + +/// A container object for all the types of maps objects. +/// +/// This is intended for use as a parameter in platform interface methods, to +/// allow adding new object types to existing methods. +@immutable +class MapObjects { + /// Creates a new set of map objects with all the given object types. + const MapObjects({ + this.markers = const {}, + this.polygons = const {}, + this.polylines = const {}, + this.circles = const {}, + this.tileOverlays = const {}, + }); + + final Set markers; + final Set polygons; + final Set polylines; + final Set circles; + final Set tileOverlays; +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_widget_configuration.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_widget_configuration.dart new file mode 100644 index 000000000000..029af9901661 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_widget_configuration.dart @@ -0,0 +1,32 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; + +import 'types.dart'; + +/// A container object for configuration options when building a widget. +/// +/// This is intended for use as a parameter in platform interface methods, to +/// allow adding new configuration options to existing methods. +@immutable +class MapWidgetConfiguration { + /// Creates a new configuration with all the given settings. + const MapWidgetConfiguration({ + required this.initialCameraPosition, + required this.textDirection, + this.gestureRecognizers = const >{}, + }); + + /// The initial camera position to display. + final CameraPosition initialCameraPosition; + + /// The text direction for the widget. + final TextDirection textDirection; + + /// Gesture recognizers to add to the widget. + final Set> gestureRecognizers; +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart index 1e1bef8ee6c0..96e8076c6f63 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart @@ -11,6 +11,7 @@ export 'circle.dart'; export 'circle_updates.dart'; export 'joint_type.dart'; export 'location.dart'; +export 'map_configuration.dart'; export 'maps_object.dart'; export 'maps_object_updates.dart'; export 'marker.dart'; @@ -25,7 +26,7 @@ export 'tile.dart'; export 'tile_overlay.dart'; export 'tile_provider.dart'; export 'ui.dart'; -// Export the utils, they're used by the Widget +// Export the utils used by the Widget export 'utils/circle.dart'; export 'utils/marker.dart'; export 'utils/polygon.dart'; 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 new file mode 100644 index 000000000000..bf931f28e49e --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/map_configuration_serialization.dart @@ -0,0 +1,62 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +import '../map_configuration.dart'; + +/// Returns a JSON representatino of [config]. +/// +/// This is intend for two purposes: +/// - Conversion of [MapConfiguration] to the map options dictionary used by +/// legacy platform interface methods. +/// - Conversion of [MapConfiguraiton] to the default method channel +/// implementation's representation. +/// +/// Both of these are parts of the public interface, so any change to the +/// representation other than adding a new field requires a breaking change to +/// the package. +Map jsonForMapConfiguration(MapConfiguration config) { + final EdgeInsets? padding = config.padding; + return { + if (config.compassEnabled != null) 'compassEnabled': config.compassEnabled!, + if (config.mapToolbarEnabled != null) + 'mapToolbarEnabled': config.mapToolbarEnabled!, + if (config.cameraTargetBounds != null) + 'cameraTargetBounds': config.cameraTargetBounds!.toJson(), + if (config.mapType != null) 'mapType': config.mapType!.index, + if (config.minMaxZoomPreference != null) + 'minMaxZoomPreference': config.minMaxZoomPreference!.toJson(), + if (config.rotateGesturesEnabled != null) + 'rotateGesturesEnabled': config.rotateGesturesEnabled!, + if (config.scrollGesturesEnabled != null) + 'scrollGesturesEnabled': config.scrollGesturesEnabled!, + if (config.tiltGesturesEnabled != null) + 'tiltGesturesEnabled': config.tiltGesturesEnabled!, + if (config.zoomControlsEnabled != null) + 'zoomControlsEnabled': config.zoomControlsEnabled!, + if (config.zoomGesturesEnabled != null) + 'zoomGesturesEnabled': config.zoomGesturesEnabled!, + if (config.liteModeEnabled != null) + 'liteModeEnabled': config.liteModeEnabled!, + if (config.trackCameraPosition != null) + 'trackCameraPosition': config.trackCameraPosition!, + if (config.myLocationEnabled != null) + 'myLocationEnabled': config.myLocationEnabled!, + if (config.myLocationButtonEnabled != null) + 'myLocationButtonEnabled': config.myLocationButtonEnabled!, + if (padding != null) + 'padding': [ + padding.top, + padding.left, + padding.bottom, + padding.right, + ], + if (config.indoorViewEnabled != null) + 'indoorEnabled': config.indoorViewEnabled!, + if (config.trafficEnabled != null) 'trafficEnabled': config.trafficEnabled!, + if (config.buildingsEnabled != null) + 'buildingsEnabled': config.buildingsEnabled!, + }; +} 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 0899bb6a8fb2..bb1cf9ee4c39 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 @@ -8,6 +8,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/map_widget_configuration.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; @@ -57,6 +58,25 @@ void main() { ); }, ); + + test( + 'default implementation of `buildViewWithConfiguration` delegates to `buildViewWithTextDirection`', + () { + final GoogleMapsFlutterPlatform platform = + BuildViewGoogleMapsFlutterPlatform(); + expect( + platform.buildViewWithConfiguration( + 0, + (_) {}, + widgetConfiguration: const MapWidgetConfiguration( + initialCameraPosition: CameraPosition(target: LatLng(0.0, 0.0)), + textDirection: TextDirection.ltr, + ), + ), + isA(), + ); + }, + ); }); } 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 new file mode 100644 index 000000000000..c63a52a6892f --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/map_configuration_test.dart @@ -0,0 +1,285 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; + +void main() { + group('diffs', () { + // A options instance with every field set, to test diffs against. + final MapConfiguration diffBase = MapConfiguration( + compassEnabled: false, + mapToolbarEnabled: false, + cameraTargetBounds: CameraTargetBounds(LatLngBounds( + northeast: const LatLng(30, 20), southwest: const LatLng(10, 40))), + mapType: MapType.normal, + minMaxZoomPreference: const MinMaxZoomPreference(1.0, 10.0), + rotateGesturesEnabled: false, + scrollGesturesEnabled: false, + tiltGesturesEnabled: false, + trackCameraPosition: false, + zoomControlsEnabled: false, + zoomGesturesEnabled: false, + liteModeEnabled: false, + myLocationEnabled: false, + myLocationButtonEnabled: false, + padding: const EdgeInsets.all(5.0), + indoorViewEnabled: false, + trafficEnabled: false, + buildingsEnabled: false, + ); + + test('only include changed fields', () async { + const MapConfiguration nullOptions = MapConfiguration(); + + // Everything should be null since nothing changed. + expect(diffBase.diffFrom(diffBase), nullOptions); + }); + + test('only apply non-null fields', () async { + const MapConfiguration smallDiff = MapConfiguration(compassEnabled: true); + + final MapConfiguration updated = diffBase.applyDiff(smallDiff); + + // The diff should be updated. + expect(updated.compassEnabled, true); + // Spot check that other fields weren't stomped. + expect(updated.mapToolbarEnabled, isNot(null)); + expect(updated.cameraTargetBounds, isNot(null)); + expect(updated.mapType, isNot(null)); + expect(updated.zoomControlsEnabled, isNot(null)); + expect(updated.liteModeEnabled, isNot(null)); + expect(updated.padding, isNot(null)); + expect(updated.trafficEnabled, isNot(null)); + }); + + test('handle compassEnabled', () async { + const MapConfiguration diff = MapConfiguration(compassEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.compassEnabled, true); + }); + + test('handle mapToolbarEnabled', () async { + const MapConfiguration diff = MapConfiguration(mapToolbarEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.mapToolbarEnabled, true); + }); + + test('handle cameraTargetBounds', () async { + final CameraTargetBounds newBounds = CameraTargetBounds(LatLngBounds( + northeast: const LatLng(55, 15), southwest: const LatLng(5, 15))); + final MapConfiguration diff = + MapConfiguration(cameraTargetBounds: newBounds); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.cameraTargetBounds, newBounds); + }); + + test('handle mapType', () async { + const MapConfiguration diff = + MapConfiguration(mapType: MapType.satellite); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.mapType, MapType.satellite); + }); + + test('handle minMaxZoomPreference', () async { + const MinMaxZoomPreference newZoomPref = MinMaxZoomPreference(3.3, 4.5); + const MapConfiguration diff = + MapConfiguration(minMaxZoomPreference: newZoomPref); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.minMaxZoomPreference, newZoomPref); + }); + + test('handle rotateGesturesEnabled', () async { + const MapConfiguration diff = + MapConfiguration(rotateGesturesEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.rotateGesturesEnabled, true); + }); + + test('handle scrollGesturesEnabled', () async { + const MapConfiguration diff = + MapConfiguration(scrollGesturesEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.scrollGesturesEnabled, true); + }); + + test('handle tiltGesturesEnabled', () async { + const MapConfiguration diff = MapConfiguration(tiltGesturesEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.tiltGesturesEnabled, true); + }); + + test('handle trackCameraPosition', () async { + const MapConfiguration diff = MapConfiguration(trackCameraPosition: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.trackCameraPosition, true); + }); + + test('handle zoomControlsEnabled', () async { + const MapConfiguration diff = MapConfiguration(zoomControlsEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.zoomControlsEnabled, true); + }); + + test('handle zoomGesturesEnabled', () async { + const MapConfiguration diff = MapConfiguration(zoomGesturesEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.zoomGesturesEnabled, true); + }); + + test('handle liteModeEnabled', () async { + const MapConfiguration diff = MapConfiguration(liteModeEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.liteModeEnabled, true); + }); + + test('handle myLocationEnabled', () async { + const MapConfiguration diff = MapConfiguration(myLocationEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.myLocationEnabled, true); + }); + + test('handle myLocationButtonEnabled', () async { + const MapConfiguration diff = + MapConfiguration(myLocationButtonEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.myLocationButtonEnabled, true); + }); + + test('handle padding', () async { + const EdgeInsets newPadding = + EdgeInsets.symmetric(vertical: 1.0, horizontal: 3.0); + const MapConfiguration diff = MapConfiguration(padding: newPadding); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.padding, newPadding); + }); + + test('handle indoorViewEnabled', () async { + const MapConfiguration diff = MapConfiguration(indoorViewEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.indoorViewEnabled, true); + }); + + test('handle trafficEnabled', () async { + const MapConfiguration diff = MapConfiguration(trafficEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.trafficEnabled, true); + }); + + test('handle buildingsEnabled', () async { + const MapConfiguration diff = MapConfiguration(buildingsEnabled: true); + + 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); + // A diff applied to non-empty options should update that field. + expect(updated.buildingsEnabled, true); + }); + }); +} diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/utils/map_configuration_serialization_test.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/utils/map_configuration_serialization_test.dart new file mode 100644 index 000000000000..71a0f8c4b1b1 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/test/utils/map_configuration_serialization_test.dart @@ -0,0 +1,75 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:google_maps_flutter_platform_interface/src/types/utils/map_configuration_serialization.dart'; + +void main() { + test('empty serialization', () async { + const MapConfiguration config = MapConfiguration(); + + final Map json = jsonForMapConfiguration(config); + + expect(json.isEmpty, true); + }); + + test('complete serialization', () async { + final MapConfiguration config = MapConfiguration( + compassEnabled: false, + mapToolbarEnabled: false, + cameraTargetBounds: CameraTargetBounds(LatLngBounds( + northeast: const LatLng(30, 20), southwest: const LatLng(10, 40))), + mapType: MapType.normal, + minMaxZoomPreference: const MinMaxZoomPreference(1.0, 10.0), + rotateGesturesEnabled: false, + scrollGesturesEnabled: false, + tiltGesturesEnabled: false, + trackCameraPosition: false, + zoomControlsEnabled: false, + zoomGesturesEnabled: false, + liteModeEnabled: false, + myLocationEnabled: false, + myLocationButtonEnabled: false, + padding: const EdgeInsets.all(5.0), + indoorViewEnabled: false, + trafficEnabled: false, + buildingsEnabled: false, + ); + + final Map json = jsonForMapConfiguration(config); + + // This uses literals instead of toJson() for the expectations on + // sub-objects, because if the serialization of any of those objects were + // ever to change MapConfiguration would need to update to serialize those + // objects manually to preserve the format, in order to avoid breaking + // implementations. + expect(json, { + 'compassEnabled': false, + 'mapToolbarEnabled': false, + 'cameraTargetBounds': [ + [ + [10.0, 40.0], + [30.0, 20.0] + ] + ], + 'mapType': 1, + 'minMaxZoomPreference': [1.0, 10.0], + 'rotateGesturesEnabled': false, + 'scrollGesturesEnabled': false, + 'tiltGesturesEnabled': false, + 'zoomControlsEnabled': false, + 'zoomGesturesEnabled': false, + 'liteModeEnabled': false, + 'trackCameraPosition': false, + 'myLocationEnabled': false, + 'myLocationButtonEnabled': false, + 'padding': [5.0, 5.0, 5.0, 5.0], + 'indoorEnabled': false, + 'trafficEnabled': false, + 'buildingsEnabled': false + }); + }); +} From 56c5ec394b992ae1eb224ef8d9b851b520aca79f Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 24 May 2022 12:24:30 -0400 Subject: [PATCH 03/15] Update app-facing to use new methods, adding necessary utility method to interface --- .../lib/src/controller.dart | 5 +- .../lib/src/google_map.dart | 156 +++++------------- .../test/map_creation_test.dart | 20 +-- .../method_channel_google_maps_flutter.dart | 2 - .../google_maps_flutter_platform.dart | 2 - .../lib/src/types/map_configuration.dart | 21 +++ .../lib/src/types/types.dart | 2 + .../google_maps_flutter_platform_test.dart | 1 - .../test/types/map_configuration_test.dart | 127 ++++++++++++++ 9 files changed, 202 insertions(+), 134 deletions(-) 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 dfc6e579d560..71b1434eb293 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 @@ -102,10 +102,9 @@ class GoogleMapController { /// platform side. /// /// The returned [Future] completes after listeners have been notified. - Future _updateMapOptions(Map optionsUpdate) { - assert(optionsUpdate != null); + Future _updateMapConfiguration(MapConfiguration update) { return GoogleMapsFlutterPlatform.instance - .updateMapOptions(optionsUpdate, mapId: mapId); + .updateMapConfiguration(update, mapId: mapId); } /// Updates marker configuration. 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 8ecbfbbad499..b76d103a99f4 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 @@ -294,30 +294,34 @@ class _GoogleMapState extends State { Map _polygons = {}; Map _polylines = {}; Map _circles = {}; - late _GoogleMapOptions _googleMapOptions; + late MapConfiguration _mapConfiguration; @override Widget build(BuildContext context) { - return GoogleMapsFlutterPlatform.instance.buildViewWithTextDirection( + return GoogleMapsFlutterPlatform.instance.buildViewWithConfiguration( _mapId, onPlatformViewCreated, - textDirection: widget.layoutDirection ?? - Directionality.maybeOf(context) ?? - TextDirection.ltr, - initialCameraPosition: widget.initialCameraPosition, - markers: widget.markers, - polygons: widget.polygons, - polylines: widget.polylines, - circles: widget.circles, - gestureRecognizers: widget.gestureRecognizers, - mapOptions: _googleMapOptions.toMap(), + widgetConfiguration: MapWidgetConfiguration( + textDirection: widget.layoutDirection ?? + Directionality.maybeOf(context) ?? + TextDirection.ltr, + initialCameraPosition: widget.initialCameraPosition, + gestureRecognizers: widget.gestureRecognizers, + ), + mapObjects: MapObjects( + markers: widget.markers, + polygons: widget.polygons, + polylines: widget.polylines, + circles: widget.circles, + ), + mapConfiguration: _mapConfiguration, ); } @override void initState() { super.initState(); - _googleMapOptions = _GoogleMapOptions.fromWidget(widget); + _mapConfiguration = _configurationFromMapWidget(widget); _markers = keyByMarkerId(widget.markers); _polygons = keyByPolygonId(widget.polygons); _polylines = keyByPolylineId(widget.polylines); @@ -347,16 +351,15 @@ class _GoogleMapState extends State { } Future _updateOptions() async { - final _GoogleMapOptions newOptions = _GoogleMapOptions.fromWidget(widget); - final Map updates = - _googleMapOptions.updatesMap(newOptions); + final MapConfiguration newConfig = _configurationFromMapWidget(widget); + final MapConfiguration updates = newConfig.diffFrom(_mapConfiguration); if (updates.isEmpty) { return; } final GoogleMapController controller = await _controller.future; // ignore: unawaited_futures - controller._updateMapOptions(updates); - _googleMapOptions = newOptions; + controller._updateMapConfiguration(updates); + _mapConfiguration = newConfig; } Future _updateMarkers() async { @@ -524,98 +527,27 @@ class _GoogleMapState extends State { } } -/// Configuration options for the GoogleMaps user interface. -class _GoogleMapOptions { - _GoogleMapOptions.fromWidget(GoogleMap map) - : compassEnabled = map.compassEnabled, - mapToolbarEnabled = map.mapToolbarEnabled, - cameraTargetBounds = map.cameraTargetBounds, - mapType = map.mapType, - minMaxZoomPreference = map.minMaxZoomPreference, - rotateGesturesEnabled = map.rotateGesturesEnabled, - scrollGesturesEnabled = map.scrollGesturesEnabled, - tiltGesturesEnabled = map.tiltGesturesEnabled, - trackCameraPosition = map.onCameraMove != null, - zoomControlsEnabled = map.zoomControlsEnabled, - zoomGesturesEnabled = map.zoomGesturesEnabled, - liteModeEnabled = map.liteModeEnabled, - myLocationEnabled = map.myLocationEnabled, - myLocationButtonEnabled = map.myLocationButtonEnabled, - padding = map.padding, - indoorViewEnabled = map.indoorViewEnabled, - trafficEnabled = map.trafficEnabled, - buildingsEnabled = map.buildingsEnabled, - assert(!map.liteModeEnabled || Platform.isAndroid); - - final bool compassEnabled; - - final bool mapToolbarEnabled; - - final CameraTargetBounds cameraTargetBounds; - - final MapType mapType; - - final MinMaxZoomPreference minMaxZoomPreference; - - final bool rotateGesturesEnabled; - - final bool scrollGesturesEnabled; - - final bool tiltGesturesEnabled; - - final bool trackCameraPosition; - - final bool zoomControlsEnabled; - - final bool zoomGesturesEnabled; - - final bool liteModeEnabled; - - final bool myLocationEnabled; - - final bool myLocationButtonEnabled; - - final EdgeInsets padding; - - final bool indoorViewEnabled; - - final bool trafficEnabled; - - final bool buildingsEnabled; - - Map toMap() { - return { - 'compassEnabled': compassEnabled, - 'mapToolbarEnabled': mapToolbarEnabled, - 'cameraTargetBounds': cameraTargetBounds.toJson(), - 'mapType': mapType.index, - 'minMaxZoomPreference': minMaxZoomPreference.toJson(), - 'rotateGesturesEnabled': rotateGesturesEnabled, - 'scrollGesturesEnabled': scrollGesturesEnabled, - 'tiltGesturesEnabled': tiltGesturesEnabled, - 'zoomControlsEnabled': zoomControlsEnabled, - 'zoomGesturesEnabled': zoomGesturesEnabled, - 'liteModeEnabled': liteModeEnabled, - 'trackCameraPosition': trackCameraPosition, - 'myLocationEnabled': myLocationEnabled, - 'myLocationButtonEnabled': myLocationButtonEnabled, - 'padding': [ - padding.top, - padding.left, - padding.bottom, - padding.right, - ], - 'indoorEnabled': indoorViewEnabled, - 'trafficEnabled': trafficEnabled, - 'buildingsEnabled': buildingsEnabled, - }; - } - - Map updatesMap(_GoogleMapOptions newOptions) { - final Map prevOptionsMap = toMap(); - - return newOptions.toMap() - ..removeWhere( - (String key, dynamic value) => prevOptionsMap[key] == value); - } +/// Builds a [MapConfiguration] from the given [map]. +MapConfiguration _configurationFromMapWidget(GoogleMap map) { + assert(!map.liteModeEnabled || Platform.isAndroid); + return MapConfiguration( + compassEnabled: map.compassEnabled, + mapToolbarEnabled: map.mapToolbarEnabled, + cameraTargetBounds: map.cameraTargetBounds, + mapType: map.mapType, + minMaxZoomPreference: map.minMaxZoomPreference, + rotateGesturesEnabled: map.rotateGesturesEnabled, + scrollGesturesEnabled: map.scrollGesturesEnabled, + tiltGesturesEnabled: map.tiltGesturesEnabled, + trackCameraPosition: map.onCameraMove != null, + zoomControlsEnabled: map.zoomControlsEnabled, + zoomGesturesEnabled: map.zoomGesturesEnabled, + liteModeEnabled: map.liteModeEnabled, + myLocationEnabled: map.myLocationEnabled, + myLocationButtonEnabled: map.myLocationButtonEnabled, + padding: map.padding, + indoorViewEnabled: map.indoorViewEnabled, + trafficEnabled: map.trafficEnabled, + buildingsEnabled: map.buildingsEnabled, + ); } diff --git a/packages/google_maps_flutter/google_maps_flutter/test/map_creation_test.dart b/packages/google_maps_flutter/google_maps_flutter/test/map_creation_test.dart index 73e1e77646cd..dadd95a059ad 100644 --- a/packages/google_maps_flutter/google_maps_flutter/test/map_creation_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter/test/map_creation_test.dart @@ -5,8 +5,6 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:flutter/foundation.dart'; -import 'package:flutter/gestures.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -88,8 +86,8 @@ class TestGoogleMapsFlutterPlatform extends GoogleMapsFlutterPlatform { Future init(int mapId) async {} @override - Future updateMapOptions( - Map optionsUpdate, { + Future updateMapConfiguration( + MapConfiguration update, { required int mapId, }) async {} @@ -276,18 +274,12 @@ class TestGoogleMapsFlutterPlatform extends GoogleMapsFlutterPlatform { } @override - Widget buildView( + Widget buildViewWithConfiguration( int creationId, PlatformViewCreatedCallback onPlatformViewCreated, { - required CameraPosition initialCameraPosition, - Set markers = const {}, - Set polygons = const {}, - Set polylines = const {}, - Set circles = const {}, - Set tileOverlays = const {}, - Set>? gestureRecognizers = - const >{}, - Map mapOptions = const {}, + required MapWidgetConfiguration widgetConfiguration, + MapObjects mapObjects = const MapObjects(), + MapConfiguration mapConfiguration = const MapConfiguration(), }) { onPlatformViewCreated(0); createdIds.add(creationId); diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index 4994099d3a5e..f0c758281beb 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -11,8 +11,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; -import 'package:google_maps_flutter_platform_interface/src/types/map_objects.dart'; -import 'package:google_maps_flutter_platform_interface/src/types/map_widget_configuration.dart'; import 'package:stream_transform/stream_transform.dart'; import '../types/tile_overlay_updates.dart'; 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 17ade5d09a61..9ce25bbd64dd 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 @@ -11,8 +11,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; -import 'package:google_maps_flutter_platform_interface/src/types/map_objects.dart'; -import 'package:google_maps_flutter_platform_interface/src/types/map_widget_configuration.dart'; import 'package:google_maps_flutter_platform_interface/src/types/utils/map_configuration_serialization.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; 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 ce0519c9783a..4b43caffe5b6 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 @@ -174,6 +174,27 @@ class MapConfiguration { ); } + /// True if no options are set. + bool get isEmpty => + compassEnabled == null && + mapToolbarEnabled == null && + cameraTargetBounds == null && + mapType == null && + minMaxZoomPreference == null && + rotateGesturesEnabled == null && + scrollGesturesEnabled == null && + tiltGesturesEnabled == null && + trackCameraPosition == null && + zoomControlsEnabled == null && + zoomGesturesEnabled == null && + liteModeEnabled == null && + myLocationEnabled == null && + myLocationButtonEnabled == null && + padding == null && + indoorViewEnabled == null && + trafficEnabled == null && + buildingsEnabled == null; + @override bool operator ==(Object other) { if (identical(this, other)) { diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart index 96e8076c6f63..0beb7d747ec8 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart @@ -12,6 +12,8 @@ export 'circle_updates.dart'; export 'joint_type.dart'; export 'location.dart'; export 'map_configuration.dart'; +export 'map_objects.dart'; +export 'map_widget_configuration.dart'; export 'maps_object.dart'; export 'maps_object_updates.dart'; export 'marker.dart'; 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 bb1cf9ee4c39..d185aabe1a5c 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 @@ -8,7 +8,6 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; -import 'package:google_maps_flutter_platform_interface/src/types/map_widget_configuration.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; 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 c63a52a6892f..edd1fd091073 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 @@ -282,4 +282,131 @@ void main() { expect(updated.buildingsEnabled, true); }); }); + + group('isEmpty', () { + test('is true for empty', () async { + const MapConfiguration nullOptions = MapConfiguration(); + + expect(nullOptions.isEmpty, true); + }); + + test('is false with compassEnabled', () async { + const MapConfiguration diff = MapConfiguration(compassEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with mapToolbarEnabled', () async { + const MapConfiguration diff = MapConfiguration(mapToolbarEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with cameraTargetBounds', () async { + final CameraTargetBounds newBounds = CameraTargetBounds(LatLngBounds( + northeast: const LatLng(55, 15), southwest: const LatLng(5, 15))); + final MapConfiguration diff = + MapConfiguration(cameraTargetBounds: newBounds); + + expect(diff.isEmpty, false); + }); + + test('is false with mapType', () async { + const MapConfiguration diff = + MapConfiguration(mapType: MapType.satellite); + + expect(diff.isEmpty, false); + }); + + test('is false with minMaxZoomPreference', () async { + const MinMaxZoomPreference newZoomPref = MinMaxZoomPreference(3.3, 4.5); + const MapConfiguration diff = + MapConfiguration(minMaxZoomPreference: newZoomPref); + + expect(diff.isEmpty, false); + }); + + test('is false with rotateGesturesEnabled', () async { + const MapConfiguration diff = + MapConfiguration(rotateGesturesEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with scrollGesturesEnabled', () async { + const MapConfiguration diff = + MapConfiguration(scrollGesturesEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with tiltGesturesEnabled', () async { + const MapConfiguration diff = MapConfiguration(tiltGesturesEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with trackCameraPosition', () async { + const MapConfiguration diff = MapConfiguration(trackCameraPosition: true); + + expect(diff.isEmpty, false); + }); + + test('is false with zoomControlsEnabled', () async { + const MapConfiguration diff = MapConfiguration(zoomControlsEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with zoomGesturesEnabled', () async { + const MapConfiguration diff = MapConfiguration(zoomGesturesEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with liteModeEnabled', () async { + const MapConfiguration diff = MapConfiguration(liteModeEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with myLocationEnabled', () async { + const MapConfiguration diff = MapConfiguration(myLocationEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with myLocationButtonEnabled', () async { + const MapConfiguration diff = + MapConfiguration(myLocationButtonEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with padding', () async { + const EdgeInsets newPadding = + EdgeInsets.symmetric(vertical: 1.0, horizontal: 3.0); + const MapConfiguration diff = MapConfiguration(padding: newPadding); + + expect(diff.isEmpty, false); + }); + + test('is false with indoorViewEnabled', () async { + const MapConfiguration diff = MapConfiguration(indoorViewEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with trafficEnabled', () async { + const MapConfiguration diff = MapConfiguration(trafficEnabled: true); + + expect(diff.isEmpty, false); + }); + + test('is false with buildingsEnabled', () async { + const MapConfiguration diff = MapConfiguration(buildingsEnabled: true); + + expect(diff.isEmpty, false); + }); + }); } From 388b35eceebcb7a4c67ca573d9daebd9e773589e Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 24 May 2022 14:14:42 -0400 Subject: [PATCH 04/15] Update web --- .../google_maps_controller_test.dart | 76 ++++++++++--------- .../example/pubspec.yaml | 6 ++ .../lib/google_maps_flutter_web.dart | 1 - .../lib/src/convert.dart | 66 ++++++++-------- .../lib/src/google_maps_controller.dart | 65 ++++++++-------- .../lib/src/google_maps_flutter_web.dart | 33 +++----- 6 files changed, 124 insertions(+), 123 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 ef9136afa961..dd2520d418f6 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 @@ -40,21 +40,17 @@ void main() { GoogleMapController _createController({ CameraPosition initialCameraPosition = const CameraPosition(target: LatLng(0, 0)), - Set markers = const {}, - Set polygons = const {}, - Set polylines = const {}, - Set circles = const {}, - Map options = const {}, + MapObjects mapObjects = const MapObjects(), + MapConfiguration mapConfiguration = const MapConfiguration(), }) { return GoogleMapController( mapId: mapId, streamController: stream, - initialCameraPosition: initialCameraPosition, - markers: markers, - polygons: polygons, - polylines: polylines, - circles: circles, - mapOptions: options, + widgetConfiguration: MapWidgetConfiguration( + initialCameraPosition: initialCameraPosition, + textDirection: TextDirection.ltr), + mapObjects: mapObjects, + mapConfiguration: mapConfiguration, ); } @@ -284,7 +280,8 @@ void main() { }); testWidgets('renders initial geometry', (WidgetTester tester) async { - controller = _createController(circles: { + controller = _createController( + mapObjects: MapObjects(circles: { const Circle( circleId: CircleId('circle-1'), zIndex: 1234, @@ -327,7 +324,7 @@ void main() { LatLng(43.354469, -5.851318), LatLng(43.354762, -5.850824), ]) - }); + })); controller.debugSetOverrides( circles: circles, @@ -363,9 +360,10 @@ void main() { testWidgets('empty infoWindow does not create InfoWindow instance.', (WidgetTester tester) async { - controller = _createController(markers: { + controller = _createController( + mapObjects: MapObjects(markers: { const Marker(markerId: MarkerId('marker-1')), - }); + })); controller.debugSetOverrides( markers: markers, @@ -385,10 +383,11 @@ void main() { capturedOptions = null; }); testWidgets('translates initial options', (WidgetTester tester) async { - controller = _createController(options: { - 'mapType': 2, - 'zoomControlsEnabled': true, - }); + controller = _createController( + mapConfiguration: const MapConfiguration( + mapType: MapType.satellite, + zoomControlsEnabled: true, + )); controller.debugSetOverrides( createMap: (_, gmaps.MapOptions options) { capturedOptions = options; @@ -407,9 +406,10 @@ void main() { testWidgets('disables gestureHandling with scrollGesturesEnabled false', (WidgetTester tester) async { - controller = _createController(options: { - 'scrollGesturesEnabled': false, - }); + controller = _createController( + mapConfiguration: const MapConfiguration( + scrollGesturesEnabled: false, + )); controller.debugSetOverrides( createMap: (_, gmaps.MapOptions options) { capturedOptions = options; @@ -426,9 +426,10 @@ void main() { testWidgets('disables gestureHandling with zoomGesturesEnabled false', (WidgetTester tester) async { - controller = _createController(options: { - 'zoomGesturesEnabled': false, - }); + controller = _createController( + mapConfiguration: const MapConfiguration( + zoomGesturesEnabled: false, + )); controller.debugSetOverrides( createMap: (_, gmaps.MapOptions options) { capturedOptions = options; @@ -477,9 +478,10 @@ void main() { testWidgets('initializes with traffic layer', (WidgetTester tester) async { - controller = _createController(options: { - 'trafficEnabled': true, - }); + controller = _createController( + mapConfiguration: const MapConfiguration( + trafficEnabled: true, + )); controller.debugSetOverrides(createMap: (_, __) => map); controller.init(); expect(controller.trafficLayer, isNotNull); @@ -505,9 +507,9 @@ void main() { group('updateRawOptions', () { testWidgets('can update `options`', (WidgetTester tester) async { - controller.updateRawOptions({ - 'mapType': 2, - }); + controller.updateMapConfiguration(const MapConfiguration( + mapType: MapType.satellite, + )); expect(map.mapTypeId, gmaps.MapTypeId.SATELLITE); }); @@ -515,15 +517,15 @@ void main() { testWidgets('can turn on/off traffic', (WidgetTester tester) async { expect(controller.trafficLayer, isNull); - controller.updateRawOptions({ - 'trafficEnabled': true, - }); + controller.updateMapConfiguration(const MapConfiguration( + trafficEnabled: true, + )); expect(controller.trafficLayer, isNotNull); - controller.updateRawOptions({ - 'trafficEnabled': false, - }); + controller.updateMapConfiguration(const MapConfiguration( + trafficEnabled: false, + )); expect(controller.trafficLayer, isNull); }); 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 fb6359fe5b8f..fa57e66be07f 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 @@ -21,7 +21,13 @@ dev_dependencies: google_maps: ^6.1.0 google_maps_flutter: # Used for projection_test.dart path: ../../google_maps_flutter + google_maps_flutter_platform_interface: ^2.1.2 http: ^0.13.0 integration_test: sdk: flutter mockito: ^5.0.0 + +# FOR TESTING ONLY. DO NOT MERGE. +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/lib/google_maps_flutter_web.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart index 7ae646687f19..0650184a14d0 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart @@ -10,7 +10,6 @@ import 'dart:html'; import 'dart:js_util'; import 'package:flutter/foundation.dart'; -import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; 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 c6f3164ff207..250bb5468fa7 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 @@ -13,16 +13,6 @@ final gmaps.LatLngBounds _nullGmapsLatLngBounds = const String _defaultCssColor = '#000000'; const double _defaultCssOpacity = 0.0; -// Indices in the plugin side don't match with the ones -// in the gmaps lib. This translates from plugin -> gmaps. -final Map _mapTypeToMapTypeId = { - 0: gmaps.MapTypeId.ROADMAP, // "none" in the plugin - 1: gmaps.MapTypeId.ROADMAP, - 2: gmaps.MapTypeId.SATELLITE, - 3: gmaps.MapTypeId.TERRAIN, - 4: gmaps.MapTypeId.HYBRID, -}; - // Converts a [Color] into a valid CSS value #RRGGBB. String _getCssColor(Color color) { if (color == null) { @@ -55,49 +45,64 @@ double _getCssOpacity(Color color) { // indoorViewEnabled seems to not have an equivalent in web // buildingsEnabled seems to not have an equivalent in web // padding seems to behave differently in web than mobile. You can't move UI elements in web. -gmaps.MapOptions _rawOptionsToGmapsOptions(Map rawOptions) { +gmaps.MapOptions _configurationAndStyleToGmapsOptions( + MapConfiguration configuration, List styles) { final gmaps.MapOptions options = gmaps.MapOptions(); - if (_mapTypeToMapTypeId.containsKey(rawOptions['mapType'])) { - options.mapTypeId = _mapTypeToMapTypeId[rawOptions['mapType']]; + if (configuration.mapType != null) { + options.mapTypeId = _gmapTypeIDForPluginType(configuration.mapType!); } - if (rawOptions['minMaxZoomPreference'] != null) { - final List minMaxPreference = - rawOptions['minMaxZoomPreference']! as List; + final MinMaxZoomPreference? zoomPreference = + configuration.minMaxZoomPreference; + if (zoomPreference != null) { options - ..minZoom = minMaxPreference[0] as num? - ..maxZoom = minMaxPreference[1] as num?; + ..minZoom = zoomPreference.minZoom + ..maxZoom = zoomPreference.maxZoom; } - if (rawOptions['cameraTargetBounds'] != null) { + if (configuration.cameraTargetBounds != null) { // Needs gmaps.MapOptions.restriction and gmaps.MapRestriction // see: https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions.restriction } - if (rawOptions['zoomControlsEnabled'] != null) { - options.zoomControl = rawOptions['zoomControlsEnabled'] as bool?; - } - - if (rawOptions['styles'] != null) { - options.styles = rawOptions['styles'] as List?; + if (configuration.zoomControlsEnabled != null) { + options.zoomControl = configuration.zoomControlsEnabled; } - if (rawOptions['scrollGesturesEnabled'] == false || - rawOptions['zoomGesturesEnabled'] == false) { + if (configuration.scrollGesturesEnabled == false || + configuration.zoomGesturesEnabled == false) { options.gestureHandling = 'none'; } else { options.gestureHandling = 'auto'; } - // These don't have any rawOptions entry, but they seem to be off in the native maps. + // These don't have any configuration entries, but they seem to be off in the + // native maps. options.mapTypeControl = false; options.fullscreenControl = false; options.streetViewControl = false; + options.styles = styles; + return options; } +gmaps.MapTypeId _gmapTypeIDForPluginType(MapType type) { + switch (type) { + case MapType.satellite: + return gmaps.MapTypeId.SATELLITE; + case MapType.terrain: + return gmaps.MapTypeId.TERRAIN; + case MapType.hybrid: + return gmaps.MapTypeId.HYBRID; + case MapType.normal: + case MapType.none: + default: + return gmaps.MapTypeId.ROADMAP; + } +} + gmaps.MapOptions _applyInitialPosition( CameraPosition initialPosition, gmaps.MapOptions options, @@ -111,11 +116,6 @@ gmaps.MapOptions _applyInitialPosition( return options; } -// Extracts the status of the traffic layer from the rawOptions map. -bool _isTrafficLayerEnabled(Map rawOptions) { - return rawOptions['trafficEnabled'] as bool? ?? false; -} - // The keys we'd expect to see in a serialized MapTypeStyle JSON object. final Set _mapStyleKeys = { 'elementType', 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 b7e902014281..a659fb218803 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 @@ -15,20 +15,17 @@ class GoogleMapController { GoogleMapController({ required int mapId, required StreamController> streamController, - required CameraPosition initialCameraPosition, - Set markers = const {}, - Set polygons = const {}, - Set polylines = const {}, - Set circles = const {}, - Map mapOptions = const {}, + required MapWidgetConfiguration widgetConfiguration, + MapObjects mapObjects = const MapObjects(), + MapConfiguration mapConfiguration = const MapConfiguration(), }) : _mapId = mapId, _streamController = streamController, - _initialCameraPosition = initialCameraPosition, - _markers = markers, - _polygons = polygons, - _polylines = polylines, - _circles = circles, - _rawMapOptions = mapOptions { + _initialCameraPosition = widgetConfiguration.initialCameraPosition, + _markers = mapObjects.markers, + _polygons = mapObjects.polygons, + _polylines = mapObjects.polylines, + _circles = mapObjects.circles, + _lastMapConfiguration = mapConfiguration { _circlesController = CirclesController(stream: _streamController); _polygonsController = PolygonsController(stream: _streamController); _polylinesController = PolylinesController(stream: _streamController); @@ -56,9 +53,10 @@ class GoogleMapController { final Set _polygons; final Set _polylines; final Set _circles; - // The raw options passed by the user, before converting to gmaps. + // The configuraiton passed by the user, before converting to gmaps. // Caching this allows us to re-create the map faithfully when needed. - Map _rawMapOptions = {}; + MapConfiguration _lastMapConfiguration = const MapConfiguration(); + List _lastStyles = const []; // Creates the 'viewType' for the _widget String _getViewType(int mapId) => 'plugins.flutter.io/google_maps_$mapId'; @@ -158,7 +156,8 @@ class GoogleMapController { /// Failure to call this method would result in the GMap not rendering at all, /// and most of the public methods on this class no-op'ing. void init() { - gmaps.MapOptions options = _rawOptionsToGmapsOptions(_rawMapOptions); + gmaps.MapOptions options = _configurationAndStyleToGmapsOptions( + _lastMapConfiguration, _lastStyles); // Initial position can only to be set here! options = _applyInitialPosition(_initialCameraPosition, options); @@ -177,7 +176,7 @@ class GoogleMapController { polylines: _polylines, ); - _setTrafficLayer(map, _isTrafficLayerEnabled(_rawMapOptions)); + _setTrafficLayer(map, _lastMapConfiguration.trafficEnabled ?? false); } // Funnels map gmap events into the plugin's stream controller. @@ -260,27 +259,33 @@ class GoogleMapController { _polylinesController!.addPolylines(polylines); } - // Merges new options coming from the plugin into the _rawMapOptions map. + // Merges new options coming from the plugin into _lastConfiguration. // - // Returns the updated _rawMapOptions object. - Map _mergeRawOptions(Map newOptions) { - _rawMapOptions = { - ..._rawMapOptions, - ...newOptions, - }; - return _rawMapOptions; + // Returns the updated _lastConfiguration object. + MapConfiguration _mergeConfigurations(MapConfiguration update) { + _lastMapConfiguration = _lastMapConfiguration.applyDiff(update); + return _lastMapConfiguration; } - /// Updates the map options from a `Map`. + /// Updates the map options from a [MapConfiguration]. /// - /// This method converts the map into the proper [gmaps.MapOptions] - void updateRawOptions(Map optionsUpdate) { + /// 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 Map newOptions = _mergeRawOptions(optionsUpdate); + final MapConfiguration newConfiguration = _mergeConfigurations(update); + final gmaps.MapOptions newOptions = + _configurationAndStyleToGmapsOptions(newConfiguration, _lastStyles); + + _setOptions(newOptions); + _setTrafficLayer(_googleMap!, newConfiguration.trafficEnabled ?? false); + } - _setOptions(_rawOptionsToGmapsOptions(newOptions)); - _setTrafficLayer(_googleMap!, _isTrafficLayerEnabled(newOptions)); + /// Updates the map options with a new list of [styles]. + void updateStyles(List styles) { + _lastStyles = styles; + _setOptions( + _configurationAndStyleToGmapsOptions(_lastMapConfiguration, styles)); } // Sets new [gmaps.MapOptions] on the wrapped map. 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 043952d176a0..c2085a2bddfc 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 @@ -47,11 +47,11 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { /// This attempts to merge the new `optionsUpdate` passed in, with the previous /// options passed to the map (in other updates, or when creating it). @override - Future updateMapOptions( - Map optionsUpdate, { + Future updateMapConfiguration( + MapConfiguration update, { required int mapId, }) async { - _map(mapId).updateRawOptions(optionsUpdate); + _map(mapId).updateMapConfiguration(update); } /// Applies the passed in `markerUpdates` to the `mapId`. @@ -135,9 +135,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { String? mapStyle, { required int mapId, }) async { - _map(mapId).updateRawOptions({ - 'styles': _mapStyles(mapStyle), - }); + _map(mapId).updateStyles(_mapStyles(mapStyle)); } /// Returns the bounds of the current viewport. @@ -289,18 +287,12 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { } @override - Widget buildView( + Widget buildViewWithConfiguration( int creationId, PlatformViewCreatedCallback onPlatformViewCreated, { - required CameraPosition initialCameraPosition, - Set markers = const {}, - Set polygons = const {}, - Set polylines = const {}, - Set circles = const {}, - Set tileOverlays = const {}, - Set>? gestureRecognizers = - const >{}, - Map mapOptions = const {}, + required MapWidgetConfiguration widgetConfiguration, + MapObjects mapObjects = const MapObjects(), + MapConfiguration mapConfiguration = const MapConfiguration(), }) { // Bail fast if we've already rendered this map ID... if (_mapById[creationId]?.widget != null) { @@ -311,14 +303,11 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { StreamController>.broadcast(); final GoogleMapController mapController = GoogleMapController( - initialCameraPosition: initialCameraPosition, mapId: creationId, streamController: controller, - markers: markers, - polygons: polygons, - polylines: polylines, - circles: circles, - mapOptions: mapOptions, + widgetConfiguration: widgetConfiguration, + mapObjects: mapObjects, + mapConfiguration: mapConfiguration, )..init(); // Initialize the controller _mapById[creationId] = mapController; From 67b0e573f788b0b496a7c7dcca1fd2a1400c6a30 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 24 May 2022 14:25:27 -0400 Subject: [PATCH 05/15] Version bumps and changelogs --- .../google_maps_flutter/CHANGELOG.md | 4 +++- .../google_maps_flutter/pubspec.yaml | 4 ++-- .../CHANGELOG.md | 8 ++++++++ .../pubspec.yaml | 2 +- .../google_maps_flutter_web/CHANGELOG.md | 11 +++++++++-- .../google_maps_flutter_web/example/pubspec.yaml | 2 +- .../google_maps_flutter_web/pubspec.yaml | 2 +- 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md index 57d24e2196a5..7d9ea741b9e2 100644 --- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md @@ -1,5 +1,7 @@ -## NEXT +## 2.1.6 +* Switches to new platform interface versions of `buildView` and + `updateOptions`, making it compatible with `google_maps_flutter_web` 0.4.0. * Fixes iOS native unit tests on M1 devices. * Minor fixes for new analysis options. diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index dbc7b7f7a5ce..cc648090a60b 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/plugins/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.1.5 +version: 2.1.6 environment: sdk: ">=2.14.0 <3.0.0" @@ -21,7 +21,7 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 - google_maps_flutter_platform_interface: ^2.1.2 + google_maps_flutter_platform_interface: ^2.2.0 dev_dependencies: flutter_test: 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 0359bab0b7c5..14f874de4f6c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md @@ -1,3 +1,11 @@ +## 2.2.0 + +* Adds new versions of `buildView` and `updateOptions` that take a new option + class instead of a dictionary, to remove the cross-package dependency on + magic string keys. +* Adopts several parameter objects in the new `buildView` variant to + future-proof it against future changes. + ## 2.1.7 * Updates code for stricter analysis options. 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 759daf2bb1cb..2b01e6244210 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/plugins/tree/main/packages/google_maps_fl 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.1.7 +version: 2.2.0 environment: sdk: '>=2.12.0 <3.0.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 95dfaede8d92..96487686598b 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,12 @@ -## NEXT - +## 0.4.0 + +* Implements the new platform interface versions of `buildView` and + `updateOptions` with structured option types. +* **BREAKING CHANGE**: No longer implements the unstructured option dictionary + versions of those methods, so this version can only be adopted when updating + `google_maps_flutter` to a version that uses the new methods. This will be + noted in the `google_maps_flutter` changelog as adding compatibility with + ``google_maps_flutter_web` 0.4.0. * Adds `const` constructor parameters in example tests. ## 0.3.3 diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/example/pubspec.yaml index fa57e66be07f..aa9046e9bb1a 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 @@ -21,7 +21,7 @@ dev_dependencies: google_maps: ^6.1.0 google_maps_flutter: # Used for projection_test.dart path: ../../google_maps_flutter - google_maps_flutter_platform_interface: ^2.1.2 + google_maps_flutter_platform_interface: ^2.2.0 http: ^0.13.0 integration_test: sdk: flutter 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 2db1d57b6556..53bcdc3dbceb 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/plugins/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.3.3 +version: 0.4.0 environment: sdk: ">=2.12.0 <3.0.0" From 0ddc037998eb09fe724ff7511c03d7963354daba Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 25 May 2022 13:17:32 -0400 Subject: [PATCH 06/15] Don't pre-bump versions --- packages/google_maps_flutter/google_maps_flutter/pubspec.yaml | 2 +- .../google_maps_flutter_web/example/pubspec.yaml | 2 +- .../google_maps_flutter/google_maps_flutter_web/pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index cc648090a60b..e3d36441e9c1 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 - google_maps_flutter_platform_interface: ^2.2.0 + google_maps_flutter_platform_interface: ^2.1.2 # 2.2.0 dev_dependencies: flutter_test: 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 aa9046e9bb1a..3f558266a5c3 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 @@ -21,7 +21,7 @@ dev_dependencies: google_maps: ^6.1.0 google_maps_flutter: # Used for projection_test.dart path: ../../google_maps_flutter - google_maps_flutter_platform_interface: ^2.2.0 + google_maps_flutter_platform_interface: ^2.1.2 # 2.2.0 http: ^0.13.0 integration_test: sdk: flutter 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 53bcdc3dbceb..1a5fdd7ee755 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -22,7 +22,7 @@ dependencies: flutter_web_plugins: sdk: flutter google_maps: ^6.1.0 - google_maps_flutter_platform_interface: ^2.1.2 + google_maps_flutter_platform_interface: ^2.1.2 # 2.2.0 sanitize_html: ^2.0.0 stream_transform: ^2.0.0 From 9bf7782952b393731a30b4113e0cd706cad01c8f Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 10 Jun 2022 11:44:51 -0400 Subject: [PATCH 07/15] Fix typos --- .../src/types/utils/map_configuration_serialization.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 bf931f28e49e..01f4fa054570 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 @@ -6,12 +6,12 @@ import 'package:flutter/material.dart'; import '../map_configuration.dart'; -/// Returns a JSON representatino of [config]. +/// Returns a JSON representation of [config]. /// -/// This is intend for two purposes: +/// This is intended for two purposes: /// - Conversion of [MapConfiguration] to the map options dictionary used by /// legacy platform interface methods. -/// - Conversion of [MapConfiguraiton] to the default method channel +/// - Conversion of [MapConfiguration] to the default method channel /// implementation's representation. /// /// Both of these are parts of the public interface, so any change to the From 4cf719a50d8b7dcc6ab9d95418e581435ebce6cb Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Mon, 13 Jun 2022 14:36:12 -0400 Subject: [PATCH 08/15] Update test for intentionally broken functionality --- .../integration_test/google_maps_plugin_test.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart index f28a6041da2a..fcdf88af028c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart @@ -221,14 +221,13 @@ void main() { plugin.debugSetMapById({mapId: controller}); }); // Options - testWidgets('updateMapOptions', (WidgetTester tester) async { - final Map expectedMapOptions = { - 'someOption': 12345 - }; + testWidgets('updateMapConfiguration', (WidgetTester tester) async { + const MapConfiguration configuration = + MapConfiguration(mapType: MapType.satellite); - await plugin.updateMapOptions(expectedMapOptions, mapId: mapId); + await plugin.updateMapConfiguration(configuration, mapId: mapId); - verify(controller.updateRawOptions(expectedMapOptions)); + verify(controller.updateMapConfiguration(configuration)); }); // Geometry testWidgets('updateMarkers', (WidgetTester tester) async { From b018b020915d71931ad349da483e840ff4a4d3f5 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 14 Jun 2022 09:40:00 -0400 Subject: [PATCH 09/15] Replace overrides with published version --- .../google_maps_flutter/google_maps_flutter/pubspec.yaml | 8 +------- .../google_maps_flutter_web/example/pubspec.yaml | 6 ------ .../google_maps_flutter_web/pubspec.yaml | 8 +------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 28720198781d..1a0dd4ebfc6f 100644 --- a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 - google_maps_flutter_platform_interface: ^2.1.2 # 2.2.0 + google_maps_flutter_platform_interface: ^2.2.0 dev_dependencies: flutter_test: @@ -30,9 +30,3 @@ dev_dependencies: pedantic: ^1.10.0 plugin_platform_interface: ^2.0.0 stream_transform: ^2.0.0 - - -# FOR TESTING ONLY. DO NOT MERGE. -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 3f558266a5c3..fb6359fe5b8f 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 @@ -21,13 +21,7 @@ dev_dependencies: google_maps: ^6.1.0 google_maps_flutter: # Used for projection_test.dart path: ../../google_maps_flutter - google_maps_flutter_platform_interface: ^2.1.2 # 2.2.0 http: ^0.13.0 integration_test: sdk: flutter mockito: ^5.0.0 - -# FOR TESTING ONLY. DO NOT MERGE. -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/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml index 1a5fdd7ee755..a05be66b83ba 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -22,7 +22,7 @@ dependencies: flutter_web_plugins: sdk: flutter google_maps: ^6.1.0 - google_maps_flutter_platform_interface: ^2.1.2 # 2.2.0 + google_maps_flutter_platform_interface: ^2.2.0 sanitize_html: ^2.0.0 stream_transform: ^2.0.0 @@ -33,9 +33,3 @@ dev_dependencies: # The example deliberately includes limited-use secrets. false_secrets: - /example/web/index.html - - -# FOR TESTING ONLY. DO NOT MERGE. -dependency_overrides: - google_maps_flutter_platform_interface: - path: ../../google_maps_flutter/google_maps_flutter_platform_interface From 26c125279ada715b2539ee6405d083861b95633c Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 14 Jun 2022 09:40:54 -0400 Subject: [PATCH 10/15] Revert non-web changes --- .../google_maps_flutter/CHANGELOG.md | 4 +- .../lib/src/controller.dart | 5 +- .../lib/src/google_map.dart | 156 +++++++++++++----- .../google_maps_flutter/pubspec.yaml | 4 +- .../test/map_creation_test.dart | 20 ++- 5 files changed, 132 insertions(+), 57 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md index 80a2e5d88dce..d09aa4d8bd07 100644 --- a/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md @@ -1,7 +1,5 @@ -## 2.1.8 +## NEXT -* Switches to new platform interface versions of `buildView` and - `updateOptions`, making it compatible with `google_maps_flutter_web` 0.4.0. * Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/104231). ## 2.1.7 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 71b1434eb293..dfc6e579d560 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 @@ -102,9 +102,10 @@ class GoogleMapController { /// platform side. /// /// The returned [Future] completes after listeners have been notified. - Future _updateMapConfiguration(MapConfiguration update) { + Future _updateMapOptions(Map optionsUpdate) { + assert(optionsUpdate != null); return GoogleMapsFlutterPlatform.instance - .updateMapConfiguration(update, mapId: mapId); + .updateMapOptions(optionsUpdate, mapId: mapId); } /// Updates marker configuration. 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 b76d103a99f4..8ecbfbbad499 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 @@ -294,34 +294,30 @@ class _GoogleMapState extends State { Map _polygons = {}; Map _polylines = {}; Map _circles = {}; - late MapConfiguration _mapConfiguration; + late _GoogleMapOptions _googleMapOptions; @override Widget build(BuildContext context) { - return GoogleMapsFlutterPlatform.instance.buildViewWithConfiguration( + return GoogleMapsFlutterPlatform.instance.buildViewWithTextDirection( _mapId, onPlatformViewCreated, - widgetConfiguration: MapWidgetConfiguration( - textDirection: widget.layoutDirection ?? - Directionality.maybeOf(context) ?? - TextDirection.ltr, - initialCameraPosition: widget.initialCameraPosition, - gestureRecognizers: widget.gestureRecognizers, - ), - mapObjects: MapObjects( - markers: widget.markers, - polygons: widget.polygons, - polylines: widget.polylines, - circles: widget.circles, - ), - mapConfiguration: _mapConfiguration, + textDirection: widget.layoutDirection ?? + Directionality.maybeOf(context) ?? + TextDirection.ltr, + initialCameraPosition: widget.initialCameraPosition, + markers: widget.markers, + polygons: widget.polygons, + polylines: widget.polylines, + circles: widget.circles, + gestureRecognizers: widget.gestureRecognizers, + mapOptions: _googleMapOptions.toMap(), ); } @override void initState() { super.initState(); - _mapConfiguration = _configurationFromMapWidget(widget); + _googleMapOptions = _GoogleMapOptions.fromWidget(widget); _markers = keyByMarkerId(widget.markers); _polygons = keyByPolygonId(widget.polygons); _polylines = keyByPolylineId(widget.polylines); @@ -351,15 +347,16 @@ class _GoogleMapState extends State { } Future _updateOptions() async { - final MapConfiguration newConfig = _configurationFromMapWidget(widget); - final MapConfiguration updates = newConfig.diffFrom(_mapConfiguration); + final _GoogleMapOptions newOptions = _GoogleMapOptions.fromWidget(widget); + final Map updates = + _googleMapOptions.updatesMap(newOptions); if (updates.isEmpty) { return; } final GoogleMapController controller = await _controller.future; // ignore: unawaited_futures - controller._updateMapConfiguration(updates); - _mapConfiguration = newConfig; + controller._updateMapOptions(updates); + _googleMapOptions = newOptions; } Future _updateMarkers() async { @@ -527,27 +524,98 @@ class _GoogleMapState extends State { } } -/// Builds a [MapConfiguration] from the given [map]. -MapConfiguration _configurationFromMapWidget(GoogleMap map) { - assert(!map.liteModeEnabled || Platform.isAndroid); - return MapConfiguration( - compassEnabled: map.compassEnabled, - mapToolbarEnabled: map.mapToolbarEnabled, - cameraTargetBounds: map.cameraTargetBounds, - mapType: map.mapType, - minMaxZoomPreference: map.minMaxZoomPreference, - rotateGesturesEnabled: map.rotateGesturesEnabled, - scrollGesturesEnabled: map.scrollGesturesEnabled, - tiltGesturesEnabled: map.tiltGesturesEnabled, - trackCameraPosition: map.onCameraMove != null, - zoomControlsEnabled: map.zoomControlsEnabled, - zoomGesturesEnabled: map.zoomGesturesEnabled, - liteModeEnabled: map.liteModeEnabled, - myLocationEnabled: map.myLocationEnabled, - myLocationButtonEnabled: map.myLocationButtonEnabled, - padding: map.padding, - indoorViewEnabled: map.indoorViewEnabled, - trafficEnabled: map.trafficEnabled, - buildingsEnabled: map.buildingsEnabled, - ); +/// Configuration options for the GoogleMaps user interface. +class _GoogleMapOptions { + _GoogleMapOptions.fromWidget(GoogleMap map) + : compassEnabled = map.compassEnabled, + mapToolbarEnabled = map.mapToolbarEnabled, + cameraTargetBounds = map.cameraTargetBounds, + mapType = map.mapType, + minMaxZoomPreference = map.minMaxZoomPreference, + rotateGesturesEnabled = map.rotateGesturesEnabled, + scrollGesturesEnabled = map.scrollGesturesEnabled, + tiltGesturesEnabled = map.tiltGesturesEnabled, + trackCameraPosition = map.onCameraMove != null, + zoomControlsEnabled = map.zoomControlsEnabled, + zoomGesturesEnabled = map.zoomGesturesEnabled, + liteModeEnabled = map.liteModeEnabled, + myLocationEnabled = map.myLocationEnabled, + myLocationButtonEnabled = map.myLocationButtonEnabled, + padding = map.padding, + indoorViewEnabled = map.indoorViewEnabled, + trafficEnabled = map.trafficEnabled, + buildingsEnabled = map.buildingsEnabled, + assert(!map.liteModeEnabled || Platform.isAndroid); + + final bool compassEnabled; + + final bool mapToolbarEnabled; + + final CameraTargetBounds cameraTargetBounds; + + final MapType mapType; + + final MinMaxZoomPreference minMaxZoomPreference; + + final bool rotateGesturesEnabled; + + final bool scrollGesturesEnabled; + + final bool tiltGesturesEnabled; + + final bool trackCameraPosition; + + final bool zoomControlsEnabled; + + final bool zoomGesturesEnabled; + + final bool liteModeEnabled; + + final bool myLocationEnabled; + + final bool myLocationButtonEnabled; + + final EdgeInsets padding; + + final bool indoorViewEnabled; + + final bool trafficEnabled; + + final bool buildingsEnabled; + + Map toMap() { + return { + 'compassEnabled': compassEnabled, + 'mapToolbarEnabled': mapToolbarEnabled, + 'cameraTargetBounds': cameraTargetBounds.toJson(), + 'mapType': mapType.index, + 'minMaxZoomPreference': minMaxZoomPreference.toJson(), + 'rotateGesturesEnabled': rotateGesturesEnabled, + 'scrollGesturesEnabled': scrollGesturesEnabled, + 'tiltGesturesEnabled': tiltGesturesEnabled, + 'zoomControlsEnabled': zoomControlsEnabled, + 'zoomGesturesEnabled': zoomGesturesEnabled, + 'liteModeEnabled': liteModeEnabled, + 'trackCameraPosition': trackCameraPosition, + 'myLocationEnabled': myLocationEnabled, + 'myLocationButtonEnabled': myLocationButtonEnabled, + 'padding': [ + padding.top, + padding.left, + padding.bottom, + padding.right, + ], + 'indoorEnabled': indoorViewEnabled, + 'trafficEnabled': trafficEnabled, + 'buildingsEnabled': buildingsEnabled, + }; + } + + Map updatesMap(_GoogleMapOptions newOptions) { + final Map prevOptionsMap = toMap(); + + return newOptions.toMap() + ..removeWhere( + (String key, dynamic value) => prevOptionsMap[key] == value); + } } diff --git a/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter/pubspec.yaml index 1a0dd4ebfc6f..215a930c91b9 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/plugins/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.1.8 +version: 2.1.7 environment: sdk: ">=2.14.0 <3.0.0" @@ -21,7 +21,7 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.1 - google_maps_flutter_platform_interface: ^2.2.0 + google_maps_flutter_platform_interface: ^2.1.2 dev_dependencies: flutter_test: diff --git a/packages/google_maps_flutter/google_maps_flutter/test/map_creation_test.dart b/packages/google_maps_flutter/google_maps_flutter/test/map_creation_test.dart index b34fccbfa422..2b03d785953b 100644 --- a/packages/google_maps_flutter/google_maps_flutter/test/map_creation_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter/test/map_creation_test.dart @@ -7,6 +7,8 @@ import 'dart:async'; // ignore: unnecessary_import import 'dart:typed_data'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -88,8 +90,8 @@ class TestGoogleMapsFlutterPlatform extends GoogleMapsFlutterPlatform { Future init(int mapId) async {} @override - Future updateMapConfiguration( - MapConfiguration update, { + Future updateMapOptions( + Map optionsUpdate, { required int mapId, }) async {} @@ -276,12 +278,18 @@ class TestGoogleMapsFlutterPlatform extends GoogleMapsFlutterPlatform { } @override - Widget buildViewWithConfiguration( + Widget buildView( int creationId, PlatformViewCreatedCallback onPlatformViewCreated, { - required MapWidgetConfiguration widgetConfiguration, - MapObjects mapObjects = const MapObjects(), - MapConfiguration mapConfiguration = const MapConfiguration(), + required CameraPosition initialCameraPosition, + Set markers = const {}, + Set polygons = const {}, + Set polylines = const {}, + Set circles = const {}, + Set tileOverlays = const {}, + Set>? gestureRecognizers = + const >{}, + Map mapOptions = const {}, }) { onPlatformViewCreated(0); createdIds.add(creationId); From a8e0a45c899b1094a397dae0d167d6cf39ec4125 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 14 Jun 2022 09:42:44 -0400 Subject: [PATCH 11/15] Typo fix --- .../google_maps_flutter/google_maps_flutter_web/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 96487686598b..09091b271be6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -6,7 +6,7 @@ versions of those methods, so this version can only be adopted when updating `google_maps_flutter` to a version that uses the new methods. This will be noted in the `google_maps_flutter` changelog as adding compatibility with - ``google_maps_flutter_web` 0.4.0. + `google_maps_flutter_web` 0.4.0. * Adds `const` constructor parameters in example tests. ## 0.3.3 From ab6971750177518255315dc8f7c44431a24d46cd Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 14 Jun 2022 11:58:57 -0400 Subject: [PATCH 12/15] Update mocks and tests --- .../google_maps_plugin_test.dart | 26 ++++++++++++------- .../google_maps_plugin_test.mocks.dart | 9 +++++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart index fcdf88af028c..e66a3f47c78c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.dart @@ -79,10 +79,13 @@ void main() { {}; plugin.debugSetMapById(cache); - final Widget widget = plugin.buildView( + final Widget widget = plugin.buildViewWithConfiguration( testMapId, onPlatformViewCreated, - initialCameraPosition: initialCameraPosition, + widgetConfiguration: const MapWidgetConfiguration( + initialCameraPosition: initialCameraPosition, + textDirection: TextDirection.ltr, + ), ); expect(widget, isA()); @@ -114,10 +117,13 @@ void main() { testMapId: controller, }); - final Widget widget = plugin.buildView( + final Widget widget = plugin.buildViewWithConfiguration( testMapId, onPlatformViewCreated, - initialCameraPosition: initialCameraPosition, + widgetConfiguration: const MapWidgetConfiguration( + initialCameraPosition: initialCameraPosition, + textDirection: TextDirection.ltr, + ), ); expect(widget, equals(expected)); @@ -130,10 +136,13 @@ void main() { {}; plugin.debugSetMapById(cache); - plugin.buildView( + plugin.buildViewWithConfiguration( testMapId, onPlatformViewCreated, - initialCameraPosition: initialCameraPosition, + widgetConfiguration: const MapWidgetConfiguration( + initialCameraPosition: initialCameraPosition, + textDirection: TextDirection.ltr, + ), ); // Simulate Google Maps JS SDK being "ready" @@ -176,11 +185,10 @@ void main() { await plugin.setMapStyle(mapStyle, mapId: 0); final dynamic captured = - verify(controller.updateRawOptions(captureThat(isMap))).captured[0]; + verify(controller.updateStyles(captureThat(isList))).captured[0]; - expect(captured, contains('styles')); final List styles = - captured['styles'] as List; + captured as List; expect(styles.length, 1); // Let's peek inside the styles... final gmaps.MapTypeStyle style = styles[0]; diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.mocks.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.mocks.dart index bbc92ffc6096..744552f45d4d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.mocks.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_plugin_test.mocks.dart @@ -4,6 +4,7 @@ import 'dart:async' as _i2; +import 'package:google_maps/google_maps.dart' as _i5; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart' as _i3; import 'package:google_maps_flutter_web/google_maps_flutter_web.dart' as _i4; @@ -68,8 +69,12 @@ class MockGoogleMapController extends _i1.Mock void init() => super.noSuchMethod(Invocation.method(#init, []), returnValueForMissingStub: null); @override - void updateRawOptions(Map? optionsUpdate) => - super.noSuchMethod(Invocation.method(#updateRawOptions, [optionsUpdate]), + void updateMapConfiguration(_i3.MapConfiguration? update) => + super.noSuchMethod(Invocation.method(#updateMapConfiguration, [update]), + returnValueForMissingStub: null); + @override + void updateStyles(List<_i5.MapTypeStyle>? styles) => + super.noSuchMethod(Invocation.method(#updateStyles, [styles]), returnValueForMissingStub: null); @override _i2.Future<_i3.LatLngBounds> getVisibleRegion() => (super.noSuchMethod( From a1f1c4452c039ce99d77bd679825a62e0ca6ae3a Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Tue, 14 Jun 2022 11:34:47 -0700 Subject: [PATCH 13/15] Restore a husk of buildView so an integration test can pass. --- .../lib/google_maps_flutter_web.dart | 1 + .../lib/src/google_maps_flutter_web.dart | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart index 0650184a14d0..7ae646687f19 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart @@ -10,6 +10,7 @@ import 'dart:html'; import 'dart:js_util'; import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; 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 c2085a2bddfc..be0a158ff97f 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 @@ -327,4 +327,40 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { return mapController.widget!; } + + // Only available for tests that use the `GoogleMap` widget to pass, while the + // core plugin migrates to the new MapConfiguration instead of using the mapOptions. + @Deprecated('Use buildViewWithConfiguration instead.') + @visibleForTesting + @override + Widget buildView( + int creationId, + PlatformViewCreatedCallback onPlatformViewCreated, { + required CameraPosition initialCameraPosition, + Set markers = const {}, + Set polygons = const {}, + Set polylines = const {}, + Set circles = const {}, + Set tileOverlays = const {}, + Set>? gestureRecognizers = + const >{}, + Map mapOptions = const {}, + }) { + return buildViewWithConfiguration( + creationId, + onPlatformViewCreated, + widgetConfiguration: MapWidgetConfiguration( + initialCameraPosition: initialCameraPosition, + textDirection: TextDirection.ltr, + ), + mapObjects: MapObjects( + markers: markers, + polygons: polygons, + polylines: polylines, + circles: circles, + tileOverlays: tileOverlays, + ), + mapConfiguration: const MapConfiguration(), + ); + } } From 9638a77fa0f262c71e9174a00f87525541f90349 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Tue, 14 Jun 2022 13:12:43 -0700 Subject: [PATCH 14/15] Revert "Restore a husk of buildView so an integration test can pass." This reverts commit a1f1c4452c039ce99d77bd679825a62e0ca6ae3a. --- .../lib/google_maps_flutter_web.dart | 1 - .../lib/src/google_maps_flutter_web.dart | 36 ------------------- 2 files changed, 37 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart index 7ae646687f19..0650184a14d0 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart @@ -10,7 +10,6 @@ import 'dart:html'; import 'dart:js_util'; import 'package:flutter/foundation.dart'; -import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; 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 be0a158ff97f..c2085a2bddfc 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 @@ -327,40 +327,4 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { return mapController.widget!; } - - // Only available for tests that use the `GoogleMap` widget to pass, while the - // core plugin migrates to the new MapConfiguration instead of using the mapOptions. - @Deprecated('Use buildViewWithConfiguration instead.') - @visibleForTesting - @override - Widget buildView( - int creationId, - PlatformViewCreatedCallback onPlatformViewCreated, { - required CameraPosition initialCameraPosition, - Set markers = const {}, - Set polygons = const {}, - Set polylines = const {}, - Set circles = const {}, - Set tileOverlays = const {}, - Set>? gestureRecognizers = - const >{}, - Map mapOptions = const {}, - }) { - return buildViewWithConfiguration( - creationId, - onPlatformViewCreated, - widgetConfiguration: MapWidgetConfiguration( - initialCameraPosition: initialCameraPosition, - textDirection: TextDirection.ltr, - ), - mapObjects: MapObjects( - markers: markers, - polygons: polygons, - polylines: polylines, - circles: circles, - tileOverlays: tileOverlays, - ), - mapConfiguration: const MapConfiguration(), - ); - } } From 8b587f06cb0437e8887435730501c01debf528fb Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Tue, 14 Jun 2022 16:19:53 -0400 Subject: [PATCH 15/15] Adjust changelog. --- .../google_maps_flutter_web/CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 09091b271be6..0f040ec5696c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -3,10 +3,8 @@ * Implements the new platform interface versions of `buildView` and `updateOptions` with structured option types. * **BREAKING CHANGE**: No longer implements the unstructured option dictionary - versions of those methods, so this version can only be adopted when updating - `google_maps_flutter` to a version that uses the new methods. This will be - noted in the `google_maps_flutter` changelog as adding compatibility with - `google_maps_flutter_web` 0.4.0. + versions of those methods, so this version can only be used with + `google_maps_flutter` 2.1.8 or later. * Adds `const` constructor parameters in example tests. ## 0.3.3