From 061f6d6a3b0aea03306a58b22fc76adbe3191b36 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 3 Mar 2021 11:58:32 -0500 Subject: [PATCH 01/12] Maps web compat WIP --- .../lib/src/convert.dart | 158 ++---------------- .../lib/src/google_maps_controller.dart | 61 ++++--- .../lib/src/google_maps_flutter_web.dart | 37 ++-- .../google_maps_flutter_web/pubspec.yaml | 12 +- .../google_maps_controller_integration.dart | 44 +++-- 5 files changed, 101 insertions(+), 211 deletions(-) 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 95f481a9bdc5..cab778f78f36 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 @@ -59,41 +59,39 @@ double _getCssOpacity(Color color) { // 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) { - Map optionsUpdate = rawOptions['options'] ?? {}; - gmaps.MapOptions options = gmaps.MapOptions(); - if (_mapTypeToMapTypeId.containsKey(optionsUpdate['mapType'])) { - options.mapTypeId = _mapTypeToMapTypeId[optionsUpdate['mapType']]; + if (_mapTypeToMapTypeId.containsKey(rawOptions['mapType'])) { + options.mapTypeId = _mapTypeToMapTypeId[rawOptions['mapType']]; } - if (optionsUpdate['minMaxZoomPreference'] != null) { + if (rawOptions['minMaxZoomPreference'] != null) { options - ..minZoom = optionsUpdate['minMaxZoomPreference'][0] - ..maxZoom = optionsUpdate['minMaxZoomPreference'][1]; + ..minZoom = rawOptions['minMaxZoomPreference'][0] + ..maxZoom = rawOptions['minMaxZoomPreference'][1]; } - if (optionsUpdate['cameraTargetBounds'] != null) { + if (rawOptions['cameraTargetBounds'] != null) { // Needs gmaps.MapOptions.restriction and gmaps.MapRestriction // see: https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions.restriction } - if (optionsUpdate['zoomControlsEnabled'] != null) { - options.zoomControl = optionsUpdate['zoomControlsEnabled']; + if (rawOptions['zoomControlsEnabled'] != null) { + options.zoomControl = rawOptions['zoomControlsEnabled']; } - if (optionsUpdate['styles'] != null) { - options.styles = optionsUpdate['styles']; + if (rawOptions['styles'] != null) { + options.styles = rawOptions['styles']; } - if (optionsUpdate['scrollGesturesEnabled'] == false || - optionsUpdate['zoomGesturesEnabled'] == false) { + if (rawOptions['scrollGesturesEnabled'] == false || + rawOptions['zoomGesturesEnabled'] == false) { options.gestureHandling = 'none'; } else { options.gestureHandling = 'auto'; } - // These don't have any optionUpdate entry, but they seem to be off in the native maps. + // These don't have any rawOptions entry, but they seem to be off in the native maps. options.mapTypeControl = false; options.fullscreenControl = false; options.streetViewControl = false; @@ -102,11 +100,10 @@ gmaps.MapOptions _rawOptionsToGmapsOptions(Map rawOptions) { } gmaps.MapOptions _applyInitialPosition( - Map rawOptions, + CameraPosition initialPosition, gmaps.MapOptions options, ) { // Adjust the initial position, if passed... - Map initialPosition = rawOptions['initialCameraPosition']; if (initialPosition != null) { final position = CameraPosition.fromMap(initialPosition); options.zoom = position.zoom; @@ -118,10 +115,7 @@ gmaps.MapOptions _applyInitialPosition( // Extracts the status of the traffic layer from the rawOptions map. bool _isTrafficLayerEnabled(Map rawOptions) { - if (rawOptions['options'] == null) { - return false; - } - return rawOptions['options']['trafficEnabled'] ?? false; + return rawOptions['trafficEnabled'] ?? false; } // Coverts the incoming JSON object into a List of MapTypeStyler objects. @@ -257,126 +251,6 @@ CameraPosition _gmViewportToCameraPosition(gmaps.GMap map) { ); } -Set _rawOptionsToInitialMarkers(Map rawOptions) { - final List> list = rawOptions['markersToAdd']; - Set markers = {}; - markers.addAll(list?.map((rawMarker) { - Offset offset; - LatLng position; - InfoWindow infoWindow; - BitmapDescriptor icon; - if (rawMarker['anchor'] != null) { - offset = Offset((rawMarker['anchor'][0]), (rawMarker['anchor'][1])); - } - if (rawMarker['position'] != null) { - position = LatLng.fromJson(rawMarker['position']); - } - if (rawMarker['infoWindow'] != null) { - final String title = rawMarker['infoWindow']['title']; - final String snippet = rawMarker['infoWindow']['snippet']; - if (title != null || snippet != null) { - infoWindow = InfoWindow( - title: title ?? '', - snippet: snippet ?? '', - ); - } - } - if (rawMarker['icon'] != null) { - icon = BitmapDescriptor.fromJson(rawMarker['icon']); - } - return Marker( - markerId: MarkerId(rawMarker['markerId']), - alpha: rawMarker['alpha'], - anchor: offset, - consumeTapEvents: rawMarker['consumeTapEvents'], - draggable: rawMarker['draggable'], - flat: rawMarker['flat'], - icon: icon, - infoWindow: infoWindow, - position: position ?? _nullLatLng, - rotation: rawMarker['rotation'], - visible: rawMarker['visible'], - zIndex: rawMarker['zIndex'], - ); - }) ?? - []); - return markers; -} - -Set _rawOptionsToInitialCircles(Map rawOptions) { - final List> list = rawOptions['circlesToAdd']; - Set circles = {}; - circles.addAll(list?.map((rawCircle) { - LatLng center; - if (rawCircle['center'] != null) { - center = LatLng.fromJson(rawCircle['center']); - } - return Circle( - circleId: CircleId(rawCircle['circleId']), - consumeTapEvents: rawCircle['consumeTapEvents'], - fillColor: Color(rawCircle['fillColor'] ?? _defaultFillColor), - center: center ?? _nullLatLng, - radius: rawCircle['radius'], - strokeColor: Color(rawCircle['strokeColor'] ?? _defaultStrokeColor), - strokeWidth: rawCircle['strokeWidth'], - visible: rawCircle['visible'], - zIndex: rawCircle['zIndex'], - ); - }) ?? - []); - return circles; -} - -// Unsupported on the web: endCap, jointType, patterns and startCap. -Set _rawOptionsToInitialPolylines(Map rawOptions) { - final List> list = rawOptions['polylinesToAdd']; - Set polylines = {}; - polylines.addAll(list?.map((rawPolyline) { - return Polyline( - polylineId: PolylineId(rawPolyline['polylineId']), - consumeTapEvents: rawPolyline['consumeTapEvents'], - color: Color(rawPolyline['color'] ?? _defaultStrokeColor), - geodesic: rawPolyline['geodesic'], - visible: rawPolyline['visible'], - zIndex: rawPolyline['zIndex'], - width: rawPolyline['width'], - points: rawPolyline['points'] - ?.map((rawPoint) => LatLng.fromJson(rawPoint)) - ?.toList(), - ); - }) ?? - []); - return polylines; -} - -Set _rawOptionsToInitialPolygons(Map rawOptions) { - final List> list = rawOptions['polygonsToAdd']; - Set polygons = {}; - - polygons.addAll(list?.map((rawPolygon) { - return Polygon( - polygonId: PolygonId(rawPolygon['polygonId']), - consumeTapEvents: rawPolygon['consumeTapEvents'], - fillColor: Color(rawPolygon['fillColor'] ?? _defaultFillColor), - geodesic: rawPolygon['geodesic'], - strokeColor: Color(rawPolygon['strokeColor'] ?? _defaultStrokeColor), - strokeWidth: rawPolygon['strokeWidth'], - visible: rawPolygon['visible'], - zIndex: rawPolygon['zIndex'], - points: rawPolygon['points'] - ?.map((rawPoint) => LatLng.fromJson(rawPoint)) - ?.toList(), - holes: rawPolygon['holes'] - ?.map>((List hole) => hole - ?.map((rawPoint) => LatLng.fromJson(rawPoint)) - ?.toList()) - ?.toList(), - ); - }) ?? - []); - return polygons; -} - // Convert plugin objects to gmaps.Options objects // TODO: Move to their appropriate objects, maybe make these copy constructors: // Marker.fromMarker(anotherMarker, moreOptions); @@ -550,7 +424,7 @@ gmaps.PolylineOptions _polylineOptionsFromPolyline( // Translates a [CameraUpdate] into operations on a [gmaps.GMap]. void _applyCameraUpdate(gmaps.GMap map, CameraUpdate update) { - final json = update.toJson(); + final json = update.toJson() as List; switch (json[0]) { case 'newCameraPosition': map.heading = json[1]['bearing']; 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 8195473ee6ba..a119f2aab9f2 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 @@ -14,11 +14,14 @@ class GoogleMapController { // The internal ID of the map. Used to broadcast events, DOM IDs and everything where a unique ID is needed. final int _mapId; + final CameraPosition _initialCameraPosition; + final Set _markers; + final Set _polygons; + final Set _polylines; + final Set _circles; // The raw options passed by the user, before converting to gmaps. // Caching this allows us to re-create the map faithfully when needed. - Map _rawOptions = { - 'options': {}, - }; + Map _rawMapOptions = {}; // Creates the 'viewType' for the _widget String _getViewType(int mapId) => 'plugins.flutter.io/google_maps_$mapId'; @@ -68,10 +71,23 @@ class GoogleMapController { GoogleMapController({ @required int mapId, @required StreamController streamController, - @required Map rawOptions, - }) : this._mapId = mapId, - this._streamController = streamController, - this._rawOptions = rawOptions { + @required CameraPosition initialCameraPosition, + Set markers = const {}, + Set polygons = const {}, + Set polylines = const {}, + Set circles = const {}, + Set tileOverlays = const {}, + Set> gestureRecognizers = + const >{}, + Map mapOptions = const {}, + }) : _mapId = mapId, + _streamController = streamController, + _initialCameraPosition = initialCameraPosition, + _markers = markers, + _polygons = polygons, + _polylines = polylines, + _circles = circles, + _rawMapOptions = mapOptions { _circlesController = CirclesController(stream: this._streamController); _polygonsController = PolygonsController(stream: this._streamController); _polylinesController = PolylinesController(stream: this._streamController); @@ -121,9 +137,9 @@ 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() { - var options = _rawOptionsToGmapsOptions(_rawOptions); + var options = _rawOptionsToGmapsOptions(_rawMapOptions); // Initial position can only to be set here! - options = _applyInitialPosition(_rawOptions, options); + options = _applyInitialPosition(_initialCameraPosition, options); // Create the map... _googleMap = _createMap(_div, options); @@ -132,13 +148,13 @@ class GoogleMapController { _attachGeometryControllers(_googleMap); _renderInitialGeometry( - markers: _rawOptionsToInitialMarkers(_rawOptions), - circles: _rawOptionsToInitialCircles(_rawOptions), - polygons: _rawOptionsToInitialPolygons(_rawOptions), - polylines: _rawOptionsToInitialPolylines(_rawOptions), + markers: _markers, + circles: _circles, + polygons: _polygons, + polylines: _polylines, ); - _setTrafficLayer(_googleMap, _isTrafficLayerEnabled(_rawOptions)); + _setTrafficLayer(_googleMap, _isTrafficLayerEnabled(_rawMapOptions)); } // Funnels map gmap events into the plugin's stream controller. @@ -196,20 +212,15 @@ class GoogleMapController { _polylinesController.addPolylines(polylines); } - // Merges new options coming from the plugin into the `key` entry of the _rawOptions map. + // Merges new options coming from the plugin into the _rawMapOptions map. // - // By default: `key` is 'options'. - // - // Returns the updated _rawOptions object. - Map _mergeRawOptions( - Map newOptions, { - String key = 'options', - }) { - _rawOptions[key] = { - ...(_rawOptions[key] ?? {}), + // Returns the updated _rawMapOptions object. + Map _mergeRawOptions(Map newOptions) { + _rawMapOptions = { + ..._rawMapOptions, ...newOptions, }; - return _rawOptions; + return _rawMapOptions; } /// Updates the map options from a `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 cf549e8e375e..87a61819daaa 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 @@ -260,31 +260,42 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { @override Widget buildView( - Map creationParams, - Set> gestureRecognizers, - PlatformViewCreatedCallback onPlatformViewCreated) { - int mapId = creationParams.remove('_webOnlyMapCreationId'); - - assert(mapId != null, + 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 {}, + }) { + assert(creationId != null, 'buildView needs a `_webOnlyMapCreationId` in its creationParams to prevent widget reloads in web.'); - // Bail fast if we've already rendered this mapId... - if (_mapById[mapId]?.widget != null) { - return _mapById[mapId].widget; + // Bail fast if we've already rendered this map ID... + if (_mapById[creationId]?.widget != null) { + return _mapById[creationId].widget; } final StreamController controller = StreamController.broadcast(); final mapController = GoogleMapController( - mapId: mapId, + mapId: creationId, streamController: controller, - rawOptions: creationParams, + markers: markers, + polygons: polygons, + polylines: polylines, + circles: circles, + mapOptions: mapOptions, ); - _mapById[mapId] = mapController; + _mapById[creationId] = mapController; - onPlatformViewCreated.call(mapId); + onPlatformViewCreated.call(creationId); return mapController.widget; } 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 595ca20db78d..070d06994083 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -16,18 +16,18 @@ dependencies: flutter_web_plugins: sdk: flutter meta: ^1.1.7 - google_maps_flutter_platform_interface: ^1.1.0 + google_maps_flutter_platform_interface: ^2.0.1 google_maps: ^3.4.5 - stream_transform: ^1.2.0 - sanitize_html: ^1.4.1 + stream_transform: ^2.0.0 + sanitize_html: ^2.0.0 dev_dependencies: flutter_test: sdk: flutter - http: ^0.12.2 - url_launcher: ^5.2.5 + http: ^0.13.0 + url_launcher: ^6.0.2 pedantic: ^1.8.0 - mockito: ^4.1.1 + mockito: ^5.0.0 integration_test: path: ../../integration_test diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart index 302057f0ea57..82e772d8c54d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart @@ -50,11 +50,21 @@ void main() { StreamController stream; // Creates a controller with the default mapId and stream controller, and any `options` needed. - GoogleMapController _createController({Map options}) { + GoogleMapController _createController({ + CameraPosition initialCameraPosition = const CameraPosition(target: LatLng(0,0)), + Set markers = const {}, + Set polygons = const {}, + Set polylines = const {}, + Set circles = const {},Map options,}) { return GoogleMapController( mapId: mapId, streamController: stream, - rawOptions: options ?? {}); + initialCameraPosition: initialCameraPosition, + markers: markers, + polygons: polygons, +polylines: polylines, +circles: circles, + mapOptions: options ?? {}); } setUp(() { @@ -143,19 +153,11 @@ void main() { }); testWidgets('renders initial geometry', (WidgetTester tester) async { - controller = _createController(options: { - 'circlesToAdd': [ - {'circleId': 'circle-1'} - ], - 'markersToAdd': [ - { - 'markerId': 'marker-1', - 'infoWindow': { - 'title': 'title for test', - 'snippet': 'snippet for test', - }, - }, - ], + controller = _createController( + circles: {Circle(circleId:CircleId('circle-1'))}, + markers: {Marker(markerId:MarkerId('marker-1'), infoWindow: InfoWindow(title:'title for test',snippet: 'snippet for test'))}, + + options: { 'polygonsToAdd': [ { 'polygonId': 'polygon-1', @@ -226,7 +228,7 @@ void main() { testWidgets('empty infoWindow does not create InfoWindow instance.', (WidgetTester tester) async { - controller = _createController(options: { + controller = _createController(options: {XXX 'markersToAdd': [ { 'markerId': 'marker-1', @@ -253,10 +255,8 @@ void main() { }); testWidgets('translates initial options', (WidgetTester tester) async { controller = _createController(options: { - 'options': { 'mapType': 2, 'zoomControlsEnabled': true, - } }); controller.debugSetOverrides(createMap: (_, options) { capturedOptions = options; @@ -276,9 +276,7 @@ void main() { testWidgets('disables gestureHandling with scrollGesturesEnabled false', (WidgetTester tester) async { controller = _createController(options: { - 'options': { 'scrollGesturesEnabled': false, - } }); controller.debugSetOverrides(createMap: (_, options) { capturedOptions = options; @@ -296,9 +294,7 @@ void main() { testWidgets('disables gestureHandling with zoomGesturesEnabled false', (WidgetTester tester) async { controller = _createController(options: { - 'options': { 'zoomGesturesEnabled': false, - } }); controller.debugSetOverrides(createMap: (_, options) { capturedOptions = options; @@ -331,7 +327,7 @@ void main() { testWidgets('sets initial position when passed', (WidgetTester tester) async { controller = _createController(options: { - 'initialCameraPosition': { + 'initialCameraPosition': {XXX 'target': [43.308, -5.6910], 'zoom': 12, 'bearing': 0, @@ -361,9 +357,7 @@ void main() { testWidgets('initializes with traffic layer', (WidgetTester tester) async { controller = _createController(options: { - 'options': { 'trafficEnabled': true, - } }); controller.debugSetOverrides(createMap: (_, __) => map); controller.init(); From 1f7eb8df70f3495d2ba516d88a63b74d9bf8db54 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 10:56:36 -0800 Subject: [PATCH 02/12] Fix _applyInitialPosition --- .../google_maps_flutter_web/lib/src/convert.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 cab778f78f36..6bf1a2f31c4b 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 @@ -105,10 +105,9 @@ gmaps.MapOptions _applyInitialPosition( ) { // Adjust the initial position, if passed... if (initialPosition != null) { - final position = CameraPosition.fromMap(initialPosition); - options.zoom = position.zoom; + options.zoom = initialPosition.zoom; options.center = - gmaps.LatLng(position.target.latitude, position.target.longitude); + gmaps.LatLng(initialPosition.target.latitude, initialPosition.target.longitude); } return options; } From 5caa361b4af7ec65478a1bf89bfb39e3fea05af0 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 10:57:24 -0800 Subject: [PATCH 03/12] Adapt google_maps_controller_integration to new init code. --- .../google_maps_controller_integration.dart | 138 +++++++++--------- 1 file changed, 68 insertions(+), 70 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart index 82e772d8c54d..0eca5b82d922 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart @@ -51,19 +51,22 @@ void main() { // Creates a controller with the default mapId and stream controller, and any `options` needed. GoogleMapController _createController({ - CameraPosition initialCameraPosition = const CameraPosition(target: LatLng(0,0)), - Set markers = const {}, - Set polygons = const {}, - Set polylines = const {}, - Set circles = const {},Map options,}) { + CameraPosition initialCameraPosition = + const CameraPosition(target: LatLng(0, 0)), + Set markers = const {}, + Set polygons = const {}, + Set polylines = const {}, + Set circles = const {}, + Map options, + }) { return GoogleMapController( mapId: mapId, streamController: stream, initialCameraPosition: initialCameraPosition, markers: markers, polygons: polygons, -polylines: polylines, -circles: circles, + polylines: polylines, + circles: circles, mapOptions: options ?? {}); } @@ -153,50 +156,45 @@ circles: circles, }); testWidgets('renders initial geometry', (WidgetTester tester) async { - controller = _createController( - circles: {Circle(circleId:CircleId('circle-1'))}, - markers: {Marker(markerId:MarkerId('marker-1'), infoWindow: InfoWindow(title:'title for test',snippet: 'snippet for test'))}, - - options: { - 'polygonsToAdd': [ - { - 'polygonId': 'polygon-1', - 'points': [ - [43.355114, -5.851333], - [43.354797, -5.851860], - [43.354469, -5.851318], - [43.354762, -5.850824], - ], - }, - { - 'polygonId': 'polygon-2-with-holes', - 'points': [ - [43.355114, -5.851333], - [43.354797, -5.851860], - [43.354469, -5.851318], - [43.354762, -5.850824], - ], - 'holes': [ - [ - [41.354797, -6.851860], - [41.354469, -6.851318], - [41.354762, -6.850824], - ] + controller = _createController(circles: { + Circle(circleId: CircleId('circle-1')) + }, markers: { + Marker( + markerId: MarkerId('marker-1'), + infoWindow: InfoWindow( + title: 'title for test', snippet: 'snippet for test')) + }, polygons: { + Polygon(polygonId: PolygonId('polygon-1'), points: [ + LatLng(43.355114, -5.851333), + LatLng(43.354797, -5.851860), + LatLng(43.354469, -5.851318), + LatLng(43.354762, -5.850824), + ]), + Polygon( + polygonId: PolygonId('polygon-2-with-holes'), + points: [ + LatLng(43.355114, -5.851333), + LatLng(43.354797, -5.851860), + LatLng(43.354469, -5.851318), + LatLng(43.354762, -5.850824), + ], + holes: [ + [ + LatLng(41.354797, -6.851860), + LatLng(41.354469, -6.851318), + LatLng(41.354762, -6.850824), ] - }, - ], - 'polylinesToAdd': [ - { - 'polylineId': 'polyline-1', - 'points': [ - [43.355114, -5.851333], - [43.354797, -5.851860], - [43.354469, -5.851318], - [43.354762, -5.850824], - ], - }, - ], + ], + ), + }, polylines: { + Polyline(polylineId: PolylineId('polyline-1'), points: [ + LatLng(43.355114, -5.851333), + LatLng(43.354797, -5.851860), + LatLng(43.354469, -5.851318), + LatLng(43.354762, -5.850824), + ]) }); + controller.debugSetOverrides( circles: circles, markers: markers, @@ -228,14 +226,10 @@ circles: circles, testWidgets('empty infoWindow does not create InfoWindow instance.', (WidgetTester tester) async { - controller = _createController(options: {XXX - 'markersToAdd': [ - { - 'markerId': 'marker-1', - 'infoWindow': {}, - }, - ], + controller = _createController(markers: { + Marker(markerId: MarkerId('marker-1'), infoWindow: null), }); + controller.debugSetOverrides( markers: markers, ); @@ -255,8 +249,8 @@ circles: circles, }); testWidgets('translates initial options', (WidgetTester tester) async { controller = _createController(options: { - 'mapType': 2, - 'zoomControlsEnabled': true, + 'mapType': 2, + 'zoomControlsEnabled': true, }); controller.debugSetOverrides(createMap: (_, options) { capturedOptions = options; @@ -276,7 +270,7 @@ circles: circles, testWidgets('disables gestureHandling with scrollGesturesEnabled false', (WidgetTester tester) async { controller = _createController(options: { - 'scrollGesturesEnabled': false, + 'scrollGesturesEnabled': false, }); controller.debugSetOverrides(createMap: (_, options) { capturedOptions = options; @@ -294,7 +288,7 @@ circles: circles, testWidgets('disables gestureHandling with zoomGesturesEnabled false', (WidgetTester tester) async { controller = _createController(options: { - 'zoomGesturesEnabled': false, + 'zoomGesturesEnabled': false, }); controller.debugSetOverrides(createMap: (_, options) { capturedOptions = options; @@ -311,7 +305,10 @@ circles: circles, testWidgets('does not set initial position if absent', (WidgetTester tester) async { - controller = _createController(); + controller = _createController( + initialCameraPosition: null, + ); + controller.debugSetOverrides(createMap: (_, options) { capturedOptions = options; return map; @@ -326,14 +323,15 @@ circles: circles, testWidgets('sets initial position when passed', (WidgetTester tester) async { - controller = _createController(options: { - 'initialCameraPosition': {XXX - 'target': [43.308, -5.6910], - 'zoom': 12, - 'bearing': 0, - 'tilt': 0, - } - }); + controller = _createController( + initialCameraPosition: CameraPosition( + target: LatLng(43.308, -5.6910), + zoom: 12, + bearing: 0, + tilt: 0, + ), + ); + controller.debugSetOverrides(createMap: (_, options) { capturedOptions = options; return map; @@ -357,7 +355,7 @@ circles: circles, testWidgets('initializes with traffic layer', (WidgetTester tester) async { controller = _createController(options: { - 'trafficEnabled': true, + 'trafficEnabled': true, }); controller.debugSetOverrides(createMap: (_, __) => map); controller.init(); From 9132db21e03964f8770a8e5eb3c68bc394d9681c Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 10:58:04 -0800 Subject: [PATCH 04/12] Depend on meta 1.3.0 --- .../google_maps_flutter/google_maps_flutter_web/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 070d06994083..20d078284742 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -1,7 +1,7 @@ name: google_maps_flutter_web description: Web platform implementation of google_maps_flutter homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter -version: 0.1.2 +version: 0.2.0 flutter: plugin: @@ -15,7 +15,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - meta: ^1.1.7 + meta: ^1.3.0 google_maps_flutter_platform_interface: ^2.0.1 google_maps: ^3.4.5 stream_transform: ^2.0.0 From 6c83161655d914cb02a5706d1e29865df28c876d Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 11:22:52 -0800 Subject: [PATCH 05/12] Tweak GeometryUpdates tests. --- .../google_maps_plugin_integration.dart | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart index 6276d26753a4..a989eae14326 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart @@ -70,11 +70,16 @@ void main() { group('buildView', () { final testMapId = 33930; + final initialCameraPosition = CameraPosition(target: LatLng(0, 0)); testWidgets('throws without _webOnlyMapCreationId', (WidgetTester tester) async { expect( - () => plugin.buildView({}, null, onPlatformViewCreated), + () => plugin.buildView( + null, + onPlatformViewCreated, + initialCameraPosition: initialCameraPosition, + ), throwsAssertionError, reason: '_webOnlyMapCreationId is mandatory to prevent unnecessary reloads in web.', @@ -87,9 +92,11 @@ void main() { final Map cache = {}; plugin.debugSetMapById(cache); - final HtmlElementView widget = plugin.buildView({ - '_webOnlyMapCreationId': testMapId, - }, null, onPlatformViewCreated); + final HtmlElementView widget = plugin.buildView( + testMapId, + onPlatformViewCreated, + initialCameraPosition: initialCameraPosition, + ); expect( widget.viewType, @@ -116,9 +123,11 @@ void main() { when(controller.widget).thenReturn(expected); plugin.debugSetMapById({testMapId: controller}); - final widget = plugin.buildView({ - '_webOnlyMapCreationId': testMapId, - }, null, onPlatformViewCreated); + final widget = plugin.buildView( + testMapId, + onPlatformViewCreated, + initialCameraPosition: initialCameraPosition, + ); expect(widget, equals(expected)); expect( @@ -176,28 +185,28 @@ void main() { }); // Geometry testWidgets('updateMarkers', (WidgetTester tester) async { - final expectedUpdates = MarkerUpdates.from(null, null); + final expectedUpdates = MarkerUpdates.from({}, {}); await plugin.updateMarkers(expectedUpdates, mapId: mapId); verify(controller.updateMarkers(expectedUpdates)); }); testWidgets('updatePolygons', (WidgetTester tester) async { - final expectedUpdates = PolygonUpdates.from(null, null); + final expectedUpdates = PolygonUpdates.from({}, {}); await plugin.updatePolygons(expectedUpdates, mapId: mapId); verify(controller.updatePolygons(expectedUpdates)); }); testWidgets('updatePolylines', (WidgetTester tester) async { - final expectedUpdates = PolylineUpdates.from(null, null); + final expectedUpdates = PolylineUpdates.from({}, {}); await plugin.updatePolylines(expectedUpdates, mapId: mapId); verify(controller.updatePolylines(expectedUpdates)); }); testWidgets('updateCircles', (WidgetTester tester) async { - final expectedUpdates = CircleUpdates.from(null, null); + final expectedUpdates = CircleUpdates.from({}, {}); await plugin.updateCircles(expectedUpdates, mapId: mapId); From 32dddc7a289347d649a065d13f7a673264f54c39 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 11:24:10 -0800 Subject: [PATCH 06/12] Update changelog. --- .../google_maps_flutter_web/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) 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 4277d7b02769..905557952c4a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.2.0 + +* Make this plugin compatible with the rest of null-safe plugins. + +**NOTE**: This plugin is **not** null-safe yet! + ## 0.1.2 * Update min Flutter SDK to 1.20.0. From 78fceae46da3a6868c7c9af384fbb7fd834a2a17 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 11:47:23 -0800 Subject: [PATCH 07/12] Noop Tile methods. --- .../google_maps_flutter_web/CHANGELOG.md | 1 + .../lib/src/google_maps_flutter_web.dart | 16 ++++++++++++++++ .../google_maps_plugin_integration.dart | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) 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 905557952c4a..826f1ea53023 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.2.0 * Make this plugin compatible with the rest of null-safe plugins. +* Noop tile overlays methods, so they don't crash on web. **NOTE**: This plugin is **not** null-safe yet! 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 87a61819daaa..ae1924e21786 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 @@ -86,6 +86,22 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { _map(mapId).updateCircles(circleUpdates); } + @override + Future updateTileOverlays({ + @required Set newTileOverlays, + @required int mapId, + }) async { + return; // Noop for now! + } + + @override + Future clearTileCache( + TileOverlayId tileOverlayId, { + @required int mapId, + }) async { + return; // Noop for now! + } + /// Applies the given `cameraUpdate` to the current viewport (with animation). @override Future animateCamera( diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart index a989eae14326..2277d338f610 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart @@ -168,6 +168,22 @@ void main() { }); }); + group('Noop methods:', () { + int mapId = 0; + setUp(() { + plugin.debugSetMapById({mapId: controller}); + }); + // Options + testWidgets('updateTileOverlays', (WidgetTester tester) async { + final update = plugin.updateTileOverlays(mapId: mapId, newTileOverlays: {}); + expect(update, completion(null)); + }); + testWidgets('updateTileOverlays', (WidgetTester tester) async { + final update = plugin.clearTileCache(TileOverlayId('any'), mapId: mapId); + expect(update, completion(null)); + }); + }); + // These methods only pass-through values from the plugin to the controller // so we verify them all together here... group('Pass-through methods:', () { From 10568046c9a270c55ec536ad246efe6012fe2dae Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 12:06:41 -0800 Subject: [PATCH 08/12] Pass mandatory initialCameraPosition from widget to controller. --- .../google_maps_flutter_web/lib/src/google_maps_flutter_web.dart | 1 + 1 file changed, 1 insertion(+) 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 ae1924e21786..cb2a8aa238f9 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 @@ -300,6 +300,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { StreamController.broadcast(); final mapController = GoogleMapController( + initialCameraPosition: initialCameraPosition, mapId: creationId, streamController: controller, markers: markers, From dd793aa6d34dc65161bfcf71db0b9a6445251887 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 12:09:39 -0800 Subject: [PATCH 09/12] dartfmt -w . --- .../google_maps_flutter_web/lib/src/convert.dart | 4 ++-- .../test/test_driver/google_maps_plugin_integration.dart | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) 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 6bf1a2f31c4b..687eec2e85f4 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 @@ -106,8 +106,8 @@ gmaps.MapOptions _applyInitialPosition( // Adjust the initial position, if passed... if (initialPosition != null) { options.zoom = initialPosition.zoom; - options.center = - gmaps.LatLng(initialPosition.target.latitude, initialPosition.target.longitude); + options.center = gmaps.LatLng( + initialPosition.target.latitude, initialPosition.target.longitude); } return options; } diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart index 2277d338f610..f0cae1dcdaf6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_plugin_integration.dart @@ -175,11 +175,13 @@ void main() { }); // Options testWidgets('updateTileOverlays', (WidgetTester tester) async { - final update = plugin.updateTileOverlays(mapId: mapId, newTileOverlays: {}); + final update = + plugin.updateTileOverlays(mapId: mapId, newTileOverlays: {}); expect(update, completion(null)); }); testWidgets('updateTileOverlays', (WidgetTester tester) async { - final update = plugin.clearTileCache(TileOverlayId('any'), mapId: mapId); + final update = + plugin.clearTileCache(TileOverlayId('any'), mapId: mapId); expect(update, completion(null)); }); }); From 11c801e89d702ae188296f708d1a3f41649e3bcb Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 12:12:33 -0800 Subject: [PATCH 10/12] Tweak nnbd_plugins.sh --- script/nnbd_plugins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index fb5f8eac44e9..5f35bac1e101 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -34,6 +34,8 @@ readonly NNBD_PLUGINS_LIST=( "webview_flutter" "wifi_info_flutter" "in_app_purchase" + "extension_google_sign_in_as_googleapis_auth" + "google_maps_flutter_web" # Not yet migrated, but compatible with others ) # This list contains the list of plugins that have *not* been @@ -41,8 +43,6 @@ readonly NNBD_PLUGINS_LIST=( # building the all plugins app. This list should be kept empty. readonly NON_NNBD_PLUGINS_LIST=( - "extension_google_sign_in_as_googleapis_auth" - "google_maps_flutter_web" # Not yet migrated. ) export EXCLUDED_PLUGINS_FROM_STABLE=$(IFS=, ; echo "${NNBD_PLUGINS_LIST[*]}") From 477060d2a751c9824088e3f7c3fefc6a09e47627 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 12:22:47 -0800 Subject: [PATCH 11/12] Only google maps seems to be nnbd compatible --- script/nnbd_plugins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 5f35bac1e101..5681775cdb3f 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -34,7 +34,6 @@ readonly NNBD_PLUGINS_LIST=( "webview_flutter" "wifi_info_flutter" "in_app_purchase" - "extension_google_sign_in_as_googleapis_auth" "google_maps_flutter_web" # Not yet migrated, but compatible with others ) @@ -43,6 +42,7 @@ readonly NNBD_PLUGINS_LIST=( # building the all plugins app. This list should be kept empty. readonly NON_NNBD_PLUGINS_LIST=( + "extension_google_sign_in_as_googleapis_auth" # Some deps are still clashing ) export EXCLUDED_PLUGINS_FROM_STABLE=$(IFS=, ; echo "${NNBD_PLUGINS_LIST[*]}") From c67b4231cdf76269f3e251c727e391898abc8f6e Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Mar 2021 12:38:54 -0800 Subject: [PATCH 12/12] Make analyzer happy! --- .../google_maps_flutter_web/lib/src/convert.dart | 2 -- 1 file changed, 2 deletions(-) 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 687eec2e85f4..5212679fb5fe 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 @@ -11,8 +11,6 @@ final _nullLatLngBounds = LatLngBounds( ); // Defaults taken from the Google Maps Platform SDK documentation. -final _defaultStrokeColor = Colors.black.value; -final _defaultFillColor = Colors.transparent.value; final _defaultCssColor = '#000000'; final _defaultCssOpacity = 0.0;