From 6469f3f2c6de13bc462fed942fa234f81d35a6f4 Mon Sep 17 00:00:00 2001 From: leess Date: Fri, 10 Jun 2022 13:16:01 +0900 Subject: [PATCH 1/3] [google_maps_flutter] Fix various bugs * Remove analysis_options.yaml. * google_maps_flutter version up. * Fix crash issues and bugs. Signed-off-by: leess --- packages/google_maps_flutter/CHANGELOG.md | 4 ++ .../google_maps_flutter/analysis_options.yaml | 1 - .../integration_test/google_maps_test.dart | 27 +++++++-- .../google_maps_flutter/example/pubspec.yaml | 2 +- .../google_maps_flutter/lib/src/circles.dart | 8 ++- .../google_maps_flutter/lib/src/convert.dart | 20 ++++--- .../lib/src/google_maps_controller.dart | 60 ++++++++++++++----- .../lib/src/google_maps_flutter_tizen.dart | 46 ++++++++++---- .../lib/src/polylines.dart | 4 +- packages/google_maps_flutter/pubspec.yaml | 10 ++-- 10 files changed, 128 insertions(+), 54 deletions(-) delete mode 100644 packages/google_maps_flutter/analysis_options.yaml diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md index a6280f23f..e193de987 100644 --- a/packages/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.2 + +* Fix variouse bugs. + ## 0.1.1 * Update webview_flutter_tizen to 0.3.8. diff --git a/packages/google_maps_flutter/analysis_options.yaml b/packages/google_maps_flutter/analysis_options.yaml deleted file mode 100644 index cda4f6e15..000000000 --- a/packages/google_maps_flutter/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: ../../analysis_options_legacy.yaml diff --git a/packages/google_maps_flutter/example/integration_test/google_maps_test.dart b/packages/google_maps_flutter/example/integration_test/google_maps_test.dart index 7478d7f60..a1a4251e4 100644 --- a/packages/google_maps_flutter/example/integration_test/google_maps_test.dart +++ b/packages/google_maps_flutter/example/integration_test/google_maps_test.dart @@ -4,12 +4,12 @@ import 'dart:async'; -import 'package:integration_test/integration_test.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; -import 'package:google_maps_flutter_tizen/google_maps_flutter_tizen.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:google_maps_flutter_tizen/google_maps_flutter_tizen.dart'; +import 'package:integration_test/integration_test.dart'; const LatLng _kInitialMapCenter = LatLng(0, 0); const double _kInitialZoomLevel = 5; @@ -33,14 +33,17 @@ void main() { key: key, initialCameraPosition: _kInitialCameraPosition, minMaxZoomPreference: initialZoomLevel, - onMapCreated: (GoogleMapController c) async { + onMapCreated: (GoogleMapController c) { mapId = c.mapId; }, ), )); + await tester.pumpAndSettle(); + await tester.pumpAndSettle(const Duration(seconds: 3)); + plugin = GoogleMapsFlutterPlatform.instance as GoogleMapsPlugin; - GoogleMapsController? map = plugin.debugGetMapById(mapId); + final GoogleMapsController? map = plugin.debugGetMapById(mapId); expect(map, isNotNull); MinMaxZoomPreference zoomLevel = await map!.getMinMaxZoomLevels(); @@ -53,7 +56,7 @@ void main() { initialCameraPosition: _kInitialCameraPosition, minMaxZoomPreference: finalZoomLevel, onMapCreated: (GoogleMapController controller) { - fail("OnMapCreated should get called only once."); + fail('OnMapCreated should get called only once.'); }, ), )); @@ -79,6 +82,9 @@ void main() { ), )); + await tester.pumpAndSettle(); + await tester.pumpAndSettle(const Duration(seconds: 3)); + plugin = GoogleMapsFlutterPlatform.instance as GoogleMapsPlugin; GoogleMapsController? map = plugin.debugGetMapById(mapId); expect(map, isNotNull); @@ -118,6 +124,9 @@ void main() { ), )); + await tester.pumpAndSettle(); + await tester.pumpAndSettle(const Duration(seconds: 2)); + plugin = GoogleMapsFlutterPlatform.instance as GoogleMapsPlugin; GoogleMapsController? map = plugin.debugGetMapById(mapId); expect(map, isNotNull); @@ -158,6 +167,9 @@ void main() { ), )); + await tester.pumpAndSettle(); + await tester.pumpAndSettle(const Duration(seconds: 3)); + plugin = GoogleMapsFlutterPlatform.instance as GoogleMapsPlugin; final GoogleMapsController? map = plugin.debugGetMapById(mapId); expect(map, isNotNull); @@ -306,6 +318,9 @@ void main() { ), )); + await tester.pumpAndSettle(); + await tester.pumpAndSettle(const Duration(seconds: 3)); + plugin = GoogleMapsFlutterPlatform.instance as GoogleMapsPlugin; GoogleMapsController? map = plugin.debugGetMapById(mapId); expect(map, isNotNull); @@ -525,7 +540,7 @@ void main() { // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen // in `mapRendered`. // https://github.com/flutter/flutter/issues/54758 - await Future.delayed(Duration(seconds: 3)); + await Future.delayed(const Duration(seconds: 3)); // Simple call to make sure that the app hasn't crashed. final LatLngBounds bounds1 = await controller.getVisibleRegion(); diff --git a/packages/google_maps_flutter/example/pubspec.yaml b/packages/google_maps_flutter/example/pubspec.yaml index 0196d054c..436a004ef 100644 --- a/packages/google_maps_flutter/example/pubspec.yaml +++ b/packages/google_maps_flutter/example/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: flutter: sdk: flutter - google_maps_flutter: ^2.0.8 + google_maps_flutter: ^2.1.7 google_maps_flutter_tizen: path: ../ diff --git a/packages/google_maps_flutter/lib/src/circles.dart b/packages/google_maps_flutter/lib/src/circles.dart index b6d694151..f8d496fa1 100644 --- a/packages/google_maps_flutter/lib/src/circles.dart +++ b/packages/google_maps_flutter/lib/src/circles.dart @@ -9,7 +9,7 @@ part of google_maps_flutter_tizen; class CirclesController extends GeometryController { /// Initialize the cache. The [StreamController] comes from the [GoogleMapController], and is shared with other controllers. CirclesController({ - required StreamController stream, + required StreamController> stream, }) : _streamController = stream, _circleIdToController = {}, _idToCircleId = {}; @@ -19,7 +19,7 @@ class CirclesController extends GeometryController { final Map _idToCircleId; // The stream over which circles broadcast their events - final StreamController _streamController; + final StreamController> _streamController; /// Adds a set of [Circle] objects to the cache. /// @@ -53,7 +53,8 @@ class CirclesController extends GeometryController { } void _changeCircle(Circle circle) { - final circleController = _circleIdToController[circle.circleId]; + final CircleController? circleController = + _circleIdToController[circle.circleId]; circleController?.update(_circleOptionsFromCircle(circle)); } @@ -62,6 +63,7 @@ class CirclesController extends GeometryController { circleIdsToRemove.forEach(_removeCircle); } + // Removes a circle and its controller by its [CircleId]. void _removeCircle(CircleId circleId) { final CircleController? circleController = _circleIdToController[circleId]; circleController?.remove(); diff --git a/packages/google_maps_flutter/lib/src/convert.dart b/packages/google_maps_flutter/lib/src/convert.dart index e723edf57..5c17d1c28 100644 --- a/packages/google_maps_flutter/lib/src/convert.dart +++ b/packages/google_maps_flutter/lib/src/convert.dart @@ -6,7 +6,7 @@ part of google_maps_flutter_tizen; // Indices in the plugin side don't match with the ones -Map _mapTypeToMapTypeId = { +Map _mapTypeToMapTypeId = { 0: 'roadmap', // None 1: 'roadmap', 2: 'satellite', @@ -19,7 +19,7 @@ String? _getCameraBounds(dynamic option) { return null; } - final List bound = option[0] as List; + final List bound = option[0]! as List; final LatLng? southwest = LatLng.fromJson(bound[0]); final LatLng? northeast = LatLng.fromJson(bound[1]); @@ -50,7 +50,7 @@ String _rawOptionsToString(Map rawOptions) { 'mapTypeControl: false, fullscreenControl: false, streetViewControl: false'; if (_mapTypeToMapTypeId.containsKey(rawOptions['mapType'])) { - options += ', mapTypeId: \'${_mapTypeToMapTypeId[rawOptions['mapType']]}\''; + options += ", mapTypeId: '${_mapTypeToMapTypeId[rawOptions['mapType']]}'"; } if (rawOptions['minMaxZoomPreference'] != null) { @@ -79,9 +79,9 @@ String _rawOptionsToString(Map rawOptions) { if (rawOptions['scrollGesturesEnabled'] == false || rawOptions['zoomGesturesEnabled'] == false) { - options += ', gestureHandling: \'none\''; + options += ", gestureHandling: 'none'"; } else { - options += ', gestureHandling: \'auto\''; + options += ", gestureHandling: 'auto'"; } return options; @@ -91,10 +91,12 @@ String _applyInitialPosition( CameraPosition initialPosition, String options, ) { - options += ', zoom: ${initialPosition.zoom}'; - options += - ', center: {lat: ${initialPosition.target.latitude} ,lng: ${initialPosition.target.longitude}}'; - + // Adjust the initial position, if passed... + if (initialPosition != null) { + options += ', zoom: ${initialPosition.zoom}'; + options += + ', center: {lat: ${initialPosition.target.latitude} ,lng: ${initialPosition.target.longitude}}'; + } return options; } diff --git a/packages/google_maps_flutter/lib/src/google_maps_controller.dart b/packages/google_maps_flutter/lib/src/google_maps_controller.dart index 65dd5b1a5..4054e96bc 100644 --- a/packages/google_maps_flutter/lib/src/google_maps_controller.dart +++ b/packages/google_maps_flutter/lib/src/google_maps_controller.dart @@ -10,6 +10,8 @@ class GoogleMapsController { // The internal ID of the map. Used to broadcast events, DOM IDs and everything where a unique ID is needed. final int _mapId; + bool _isFirst = false; + final CameraPosition _initialCameraPosition; final Set _markers; final Set _polygons; @@ -95,6 +97,7 @@ class GoogleMapsController { javascriptChannels: { _onBoundsChanged(), _onIdle(), + _onTilesloaded(), _onClick(), _onRightClick(), _onMarkerClick(), @@ -118,6 +121,7 @@ class GoogleMapsController { map.addListener('idle', Idle.postMessage); map.addListener('click', (event) => Click.postMessage(JSON.stringify(event))); map.addListener('rightclick', (event) => RightClick.postMessage(JSON.stringify(event))); + map.addListener('tilesloaded', Tilesloaded.postMessage); '''; await (await controller).runJavascript(command); } @@ -138,10 +142,10 @@ class GoogleMapsController { } // The StreamController used by this controller and the geometry ones. - final StreamController _streamController; + final StreamController> _streamController; /// The Stream over which this controller broadcasts events. - Stream get events => _streamController.stream; + Stream> get events => _streamController.stream; // // Geometry controllers, for different features of the map. CirclesController? _circlesController; @@ -157,15 +161,12 @@ class GoogleMapsController { /// Initializes the GoogleMapsController. GoogleMapsController({ required int mapId, - required StreamController streamController, + required StreamController> streamController, 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, @@ -190,13 +191,18 @@ class GoogleMapsController { } final LatLng center = await getCenter(); final double zoom = await getZoomLevel(); - if (!_mapIsMoving) { - _mapIsMoving = true; - _streamController.add(CameraMoveStartedEvent(_mapId)); + + if (!_streamController.isClosed) { + if (!_mapIsMoving) { + _mapIsMoving = true; + _streamController.add(CameraMoveStartedEvent(_mapId)); + } + + _streamController.add( + CameraMoveEvent( + _mapId, CameraPosition(target: center, zoom: zoom)), + ); } - _streamController.add( - CameraMoveEvent(_mapId, CameraPosition(target: center, zoom: zoom)), - ); }); } @@ -212,6 +218,22 @@ class GoogleMapsController { }); } + JavascriptChannel _onTilesloaded() { + return JavascriptChannel( + name: 'Tilesloaded', + onMessageReceived: (JavascriptMessage message) async { + if (_widget == null || _streamController == null || _isFirst) { + return; + } + try { + _streamController.add(MapReadyEvent(_mapId)); + _isFirst = true; + } catch (e) { + print('Javascript Error: $e'); + } + }); + } + JavascriptChannel _onClick() { return JavascriptChannel( name: 'Click', @@ -424,10 +446,10 @@ class GoogleMapsController { // Renders the initial sets of geometry. void _renderInitialGeometry({ - Set markers = const {}, - Set circles = const {}, - Set polygons = const {}, - Set polylines = const {}, + Set markers = const {}, + Set circles = const {}, + Set polygons = const {}, + Set polylines = const {}, }) { assert( _controllersBoundToMap, @@ -729,3 +751,9 @@ class GoogleMapsController { _streamController.close(); } } + +/// A MapEvent event fired when a [mapId] on web is interactive. +class MapReadyEvent extends MapEvent { + /// Build a WebMapReady Event for the map represented by `mapId`. + MapReadyEvent(int mapId) : super(mapId, null); +} diff --git a/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart b/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart index 07ab2f9e8..873b658de 100644 --- a/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart +++ b/packages/google_maps_flutter/lib/src/google_maps_flutter_tizen.dart @@ -17,21 +17,26 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { } // A cache of map controllers by map Id. - Map _mapById = Map(); + Map _mapById = {}; /// Get controller for debugging. @visibleForTesting GoogleMapsController? debugGetMapById(int mapId) { - return _mapById[mapId] as GoogleMapsController?; + return _mapById[mapId]; + } + + @visibleForTesting + // ignore: use_setters_to_change_properties, public_member_api_docs + void debugSetMapById(Map mapById) { + _mapById = mapById; } // Convenience getter for a stream of events filtered by their mapId. - Stream _events(int mapId) => _map(mapId).events; + Stream> _events(int mapId) => _map(mapId).events; // Convenience getter for a map controller by its mapId. GoogleMapsController _map(int mapId) { - final GoogleMapsController? controller = - _mapById[mapId] as GoogleMapsController; + final GoogleMapsController? controller = _mapById[mapId]; assert(controller != null, 'Maps cannot be retrieved before calling buildView!'); return controller!; @@ -40,6 +45,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { @override Future init(int mapId) async { _map(mapId).init(); + assert(_map(mapId) != null, 'Must call buildWidget before init!'); } /// Updates the options of a given `mapId`. @@ -241,6 +247,16 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { return _events(mapId).whereType(); } + @override + Stream onMarkerDragStart({required int mapId}) { + return _events(mapId).whereType(); + } + + @override + Stream onMarkerDrag({required int mapId}) { + return _events(mapId).whereType(); + } + @override Stream onMarkerDragEnd({required int mapId}) { return _events(mapId).whereType(); @@ -294,13 +310,13 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { }) { // Bail fast if we've already rendered this map ID... if (_mapById[creationId]?.widget != null) { - return _mapById[creationId].widget as Widget; + return _mapById[creationId]!.widget!; } - final StreamController controller = - StreamController.broadcast(); + final StreamController> controller = + StreamController>.broadcast(); - final mapController = GoogleMapsController( + final GoogleMapsController mapController = GoogleMapsController( initialCameraPosition: initialCameraPosition, mapId: creationId, streamController: controller, @@ -309,11 +325,19 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform { polylines: polylines, circles: circles, mapOptions: mapOptions, - ); + )..init(); // Initialize the controller _mapById[creationId] = mapController; - onPlatformViewCreated.call(creationId); + mapController.events + .whereType() + .first + .then((MapReadyEvent event) { + assert(creationId == event.mapId, + 'Received MapReadyEvent for the wrong map'); + // Notify the plugin now that there's a fully initialized controller. + onPlatformViewCreated.call(event.mapId); + }); assert(mapController.widget != null, 'The widget of a GoogleMapsController cannot be null before calling dispose on it.'); diff --git a/packages/google_maps_flutter/lib/src/polylines.dart b/packages/google_maps_flutter/lib/src/polylines.dart index c602ed427..684d6e40d 100644 --- a/packages/google_maps_flutter/lib/src/polylines.dart +++ b/packages/google_maps_flutter/lib/src/polylines.dart @@ -9,7 +9,7 @@ part of google_maps_flutter_tizen; class PolylinesController extends GeometryController { /// Initializes the cache. The [StreamController] comes from the [GoogleMapController], and is shared with other controllers. PolylinesController({ - required StreamController stream, + required StreamController> stream, }) : _streamController = stream, _polylineIdToController = {}, _idToPolylineId = {}; @@ -19,7 +19,7 @@ class PolylinesController extends GeometryController { final Map _idToPolylineId; // The stream over which polylines broadcast their events - final StreamController _streamController; + final StreamController> _streamController; /// Adds a set of [Polyline] objects to the cache. /// diff --git a/packages/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/pubspec.yaml index 9c668c05f..682910de3 100644 --- a/packages/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/pubspec.yaml @@ -14,12 +14,12 @@ flutter: dependencies: flutter: sdk: flutter - meta: ^1.3.0 - google_maps_flutter_platform_interface: ^2.0.1 flutter_lints: ^1.0.4 + google_maps_flutter_platform_interface: ^2.1.2 + meta: ^1.3.0 stream_transform: ^2.0.0 - webview_flutter: ^3.0.1 - webview_flutter_tizen: ^0.4.1 + webview_flutter: ^3.0.4 + webview_flutter_tizen: ^0.5.0 dev_dependencies: flutter_test: @@ -27,5 +27,5 @@ dev_dependencies: pedantic: ^1.10.0 environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.17.0 <3.0.0" flutter: ">=2.0.0" From a5efda0e9d13db816f911be212227bb5f4696bbf Mon Sep 17 00:00:00 2001 From: Seungsoo Lee Date: Mon, 13 Jun 2022 18:05:59 +0900 Subject: [PATCH 2/3] fix issues by dart analyze command Signed-off-by: Seungsoo Lee --- .../example/assets/map.html | 2 +- .../integration_test/google_maps_test.dart | 34 +-- .../example/lib/animate_camera.dart | 7 +- .../example/lib/lite_mode.dart | 7 +- .../google_maps_flutter/example/lib/main.dart | 26 +- .../example/lib/map_click.dart | 17 +- .../example/lib/map_coordinates.dart | 5 +- .../example/lib/map_ui.dart | 23 +- .../example/lib/marker_icons.dart | 13 +- .../example/lib/move_camera.dart | 6 +- .../example/lib/padding.dart | 31 +- .../google_maps_flutter/example/lib/page.dart | 3 +- .../example/lib/place_circle.dart | 18 +- .../example/lib/place_marker.dart | 272 ++++++++---------- .../example/lib/place_polygon.dart | 24 +- .../example/lib/place_polyline.dart | 81 +----- .../example/lib/scrolling_map.dart | 25 +- .../example/lib/snapshot.dart | 13 +- .../example/lib/tile_overlay.dart | 20 +- .../example/tizen/tizen-manifest.xml | 2 +- .../lib/google_maps_flutter_tizen.dart | 20 +- .../google_maps_flutter/lib/src/convert.dart | 28 +- .../lib/src/google_maps_controller.dart | 68 ++--- .../google_maps_flutter/lib/src/marker.dart | 4 +- .../google_maps_flutter/lib/src/markers.dart | 12 +- .../google_maps_flutter/lib/src/polygons.dart | 4 +- .../google_maps_flutter/lib/src/util.dart | 34 +-- 27 files changed, 370 insertions(+), 429 deletions(-) diff --git a/packages/google_maps_flutter/example/assets/map.html b/packages/google_maps_flutter/example/assets/map.html index 0bad0c96a..a76fa7472 100644 --- a/packages/google_maps_flutter/example/assets/map.html +++ b/packages/google_maps_flutter/example/assets/map.html @@ -18,7 +18,7 @@ let map; console.log("before load"); - diff --git a/packages/google_maps_flutter/example/integration_test/google_maps_test.dart b/packages/google_maps_flutter/example/integration_test/google_maps_test.dart index a1a4251e4..bdd058d64 100644 --- a/packages/google_maps_flutter/example/integration_test/google_maps_test.dart +++ b/packages/google_maps_flutter/example/integration_test/google_maps_test.dart @@ -86,7 +86,7 @@ void main() { await tester.pumpAndSettle(const Duration(seconds: 3)); plugin = GoogleMapsFlutterPlatform.instance as GoogleMapsPlugin; - GoogleMapsController? map = plugin.debugGetMapById(mapId); + final GoogleMapsController? map = plugin.debugGetMapById(mapId); expect(map, isNotNull); bool? zoomGesturesEnabled = await map!.isZoomGesturesEnabled(); @@ -99,7 +99,7 @@ void main() { initialCameraPosition: _kInitialCameraPosition, zoomGesturesEnabled: true, onMapCreated: (GoogleMapController controller) { - fail("OnMapCreated should get called only once."); + fail('OnMapCreated should get called only once.'); }, ), )); @@ -128,7 +128,7 @@ void main() { await tester.pumpAndSettle(const Duration(seconds: 2)); plugin = GoogleMapsFlutterPlatform.instance as GoogleMapsPlugin; - GoogleMapsController? map = plugin.debugGetMapById(mapId); + final GoogleMapsController? map = plugin.debugGetMapById(mapId); expect(map, isNotNull); bool? zoomControlsEnabled = await map!.isZoomControlsEnabled(); @@ -141,7 +141,7 @@ void main() { initialCameraPosition: _kInitialCameraPosition, zoomControlsEnabled: false, onMapCreated: (GoogleMapController controller) { - fail("OnMapCreated should get called only once."); + fail('OnMapCreated should get called only once.'); }, ), )); @@ -218,11 +218,11 @@ void main() { // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen // in `mapRendered`. // https://github.com/flutter/flutter/issues/54758 - await Future.delayed(Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); - ScreenCoordinate coordinate = + final ScreenCoordinate coordinate = await mapController.getScreenCoordinate(_kInitialCameraPosition.target); - Rect rect = tester.getRect(find.byKey(key)); + final Rect rect = tester.getRect(find.byKey(key)); // On Tizen, the coordinate value from the GoogleMapSdk doesn't include the devicePixelRatio`. // So we don't need to do the conversion like we did below for other platforms. @@ -284,7 +284,7 @@ void main() { // TODO(iskakaushik): non-zero padding is needed for some device configurations // https://github.com/flutter/flutter/issues/30575 - final double padding = 0; + const double padding = 0; await mapController .moveCamera(CameraUpdate.newLatLngBounds(latLngBounds, padding)); // await tester.pumpAndSettle(const Duration(seconds: 3)); @@ -322,7 +322,7 @@ void main() { await tester.pumpAndSettle(const Duration(seconds: 3)); plugin = GoogleMapsFlutterPlatform.instance as GoogleMapsPlugin; - GoogleMapsController? map = plugin.debugGetMapById(mapId); + final GoogleMapsController? map = plugin.debugGetMapById(mapId); expect(map, isNotNull); bool? isTrafficEnabled = await map!.isTrafficEnabled(); @@ -335,7 +335,7 @@ void main() { initialCameraPosition: _kInitialCameraPosition, trafficEnabled: false, onMapCreated: (GoogleMapController controller) { - fail("OnMapCreated should get called only once."); + fail('OnMapCreated should get called only once.'); }, ), )); @@ -435,7 +435,7 @@ void main() { // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen // in `mapRendered`. // https://github.com/flutter/flutter/issues/54758 - await Future.delayed(Duration(seconds: 3)); + await Future.delayed(const Duration(seconds: 3)); final LatLngBounds visibleRegion = await controller.getVisibleRegion(); final LatLng topLeft = @@ -470,7 +470,7 @@ void main() { // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen // in `mapRendered`. // https://github.com/flutter/flutter/issues/54758 - await Future.delayed(Duration(seconds: 3)); + await Future.delayed(const Duration(seconds: 3)); double zoom = await controller.getZoomLevel(); expect(zoom, _kInitialZoomLevel); @@ -502,7 +502,7 @@ void main() { // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen // in `mapRendered`. // https://github.com/flutter/flutter/issues/54758 - await Future.delayed(Duration(seconds: 3)); + await Future.delayed(const Duration(seconds: 3)); final LatLngBounds visibleRegion = await controller.getVisibleRegion(); final LatLng northWest = LatLng( @@ -554,7 +554,7 @@ void main() { infoWindow: InfoWindow(title: 'InfoWindow')); final Set markers = {marker}; - Completer controllerCompleter = + final Completer controllerCompleter = Completer(); await tester.pumpWidget(Directionality( @@ -583,9 +583,9 @@ void main() { expect(iwVisibleStatus, false); }); - testWidgets("fromAssetImage", (WidgetTester tester) async { - double pixelRatio = 2; - final ImageConfiguration imageConfiguration = + testWidgets('fromAssetImage', (WidgetTester tester) async { + const double pixelRatio = 2; + const ImageConfiguration imageConfiguration = ImageConfiguration(devicePixelRatio: pixelRatio); final BitmapDescriptor mip = await BitmapDescriptor.fromAssetImage( imageConfiguration, 'red_square.png'); diff --git a/packages/google_maps_flutter/example/lib/animate_camera.dart b/packages/google_maps_flutter/example/lib/animate_camera.dart index cc5fd257d..3975d6444 100644 --- a/packages/google_maps_flutter/example/lib/animate_camera.dart +++ b/packages/google_maps_flutter/example/lib/animate_camera.dart @@ -10,8 +10,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; class AnimateCameraPage extends GoogleMapExampleAppPage { - AnimateCameraPage() - : super(const Icon(Icons.map), 'Camera control, animated'); + const AnimateCameraPage({Key? key}) + : super(const Icon(Icons.map), 'Camera control, animated', key: key); @override Widget build(BuildContext context) { @@ -20,7 +20,7 @@ class AnimateCameraPage extends GoogleMapExampleAppPage { } class AnimateCamera extends StatefulWidget { - const AnimateCamera(); + const AnimateCamera({Key? key}) : super(key: key); @override State createState() => AnimateCameraState(); } @@ -28,6 +28,7 @@ class AnimateCamera extends StatefulWidget { class AnimateCameraState extends State { GoogleMapController? mapController; + // ignore: use_setters_to_change_properties void _onMapCreated(GoogleMapController controller) { mapController = controller; } diff --git a/packages/google_maps_flutter/example/lib/lite_mode.dart b/packages/google_maps_flutter/example/lib/lite_mode.dart index 8be3f67c0..fd95cf864 100644 --- a/packages/google_maps_flutter/example/lib/lite_mode.dart +++ b/packages/google_maps_flutter/example/lib/lite_mode.dart @@ -12,7 +12,8 @@ const CameraPosition _kInitialPosition = CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0); class LiteModePage extends GoogleMapExampleAppPage { - LiteModePage() : super(const Icon(Icons.map), 'Lite mode'); + const LiteModePage({Key? key}) + : super(const Icon(Icons.map), 'Lite mode', key: key); @override Widget build(BuildContext context) { @@ -25,9 +26,9 @@ class _LiteModeBody extends StatelessWidget { @override Widget build(BuildContext context) { - return Card( + return const Card( child: Padding( - padding: const EdgeInsets.symmetric(vertical: 30.0), + padding: EdgeInsets.symmetric(vertical: 30.0), child: Center( child: SizedBox( width: 300.0, diff --git a/packages/google_maps_flutter/example/lib/main.dart b/packages/google_maps_flutter/example/lib/main.dart index e52ebc367..4efe56ac2 100644 --- a/packages/google_maps_flutter/example/lib/main.dart +++ b/packages/google_maps_flutter/example/lib/main.dart @@ -18,19 +18,23 @@ import 'place_polygon.dart'; import 'place_polyline.dart'; final List _allPages = [ - MapUiPage(), - MapCoordinatesPage(), - MapClickPage(), - AnimateCameraPage(), - MoveCameraPage(), - PlaceMarkerPage(), - MarkerIconsPage(), - PlacePolylinePage(), - PlacePolygonPage(), - PlaceCirclePage(), + const MapUiPage(), + const MapCoordinatesPage(), + const MapClickPage(), + const AnimateCameraPage(), + const MoveCameraPage(), + const PlaceMarkerPage(), + const MarkerIconsPage(), + const PlacePolylinePage(), + const PlacePolygonPage(), + const PlaceCirclePage(), ]; +/// MapsDemo is the Main Application. class MapsDemo extends StatelessWidget { + /// Default Constructor + const MapsDemo({Key? key}) : super(key: key); + void _pushPage(BuildContext context, GoogleMapExampleAppPage page) { Navigator.of(context).push(MaterialPageRoute( builder: (_) => Scaffold( @@ -56,5 +60,5 @@ class MapsDemo extends StatelessWidget { } void main() { - runApp(MaterialApp(home: MapsDemo())); + runApp(const MaterialApp(home: MapsDemo())); } diff --git a/packages/google_maps_flutter/example/lib/map_click.dart b/packages/google_maps_flutter/example/lib/map_click.dart index e07764460..ad259cd8c 100644 --- a/packages/google_maps_flutter/example/lib/map_click.dart +++ b/packages/google_maps_flutter/example/lib/map_click.dart @@ -12,7 +12,8 @@ const CameraPosition _kInitialPosition = CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0); class MapClickPage extends GoogleMapExampleAppPage { - MapClickPage() : super(const Icon(Icons.mouse), 'Map click'); + const MapClickPage({Key? key}) + : super(const Icon(Icons.mouse), 'Map click', key: key); @override Widget build(BuildContext context) { @@ -67,8 +68,16 @@ class _MapClickBodyState extends State<_MapClickBody> { if (mapController != null) { final String lastTap = 'Tap:\n${_lastTap ?? ""}\n'; final String lastLongPress = 'Long press:\n${_lastLongPress ?? ""}'; - columnChildren - .add(Center(child: Text(lastTap, textAlign: TextAlign.center))); + columnChildren.add(Center( + child: Text( + lastTap, + textAlign: TextAlign.center, + ))); + columnChildren.add(Center( + child: Text( + _lastTap != null ? 'Tapped' : '', + textAlign: TextAlign.center, + ))); columnChildren.add(Center( child: Text( lastLongPress, @@ -83,7 +92,7 @@ class _MapClickBodyState extends State<_MapClickBody> { ); } - void onMapCreated(GoogleMapController controller) async { + Future onMapCreated(GoogleMapController controller) async { setState(() { mapController = controller; }); diff --git a/packages/google_maps_flutter/example/lib/map_coordinates.dart b/packages/google_maps_flutter/example/lib/map_coordinates.dart index 51c81dba1..1179acd46 100644 --- a/packages/google_maps_flutter/example/lib/map_coordinates.dart +++ b/packages/google_maps_flutter/example/lib/map_coordinates.dart @@ -12,7 +12,8 @@ const CameraPosition _kInitialPosition = CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0); class MapCoordinatesPage extends GoogleMapExampleAppPage { - MapCoordinatesPage() : super(const Icon(Icons.map), 'Map coordinates'); + const MapCoordinatesPage({Key? key}) + : super(const Icon(Icons.map), 'Map coordinates', key: key); @override Widget build(BuildContext context) { @@ -71,7 +72,7 @@ class _MapCoordinatesBodyState extends State<_MapCoordinatesBody> { ); } - void onMapCreated(GoogleMapController controller) async { + Future onMapCreated(GoogleMapController controller) async { final LatLngBounds visibleRegion = await controller.getVisibleRegion(); setState(() { mapController = controller; diff --git a/packages/google_maps_flutter/example/lib/map_ui.dart b/packages/google_maps_flutter/example/lib/map_ui.dart index fb98f00ce..4a6a04307 100644 --- a/packages/google_maps_flutter/example/lib/map_ui.dart +++ b/packages/google_maps_flutter/example/lib/map_ui.dart @@ -16,7 +16,8 @@ final LatLngBounds sydneyBounds = LatLngBounds( ); class MapUiPage extends GoogleMapExampleAppPage { - MapUiPage() : super(const Icon(Icons.map), 'User interface'); + const MapUiPage({Key? key}) + : super(const Icon(Icons.map), 'User interface', key: key); @override Widget build(BuildContext context) { @@ -25,7 +26,7 @@ class MapUiPage extends GoogleMapExampleAppPage { } class MapUiBody extends StatefulWidget { - const MapUiBody(); + const MapUiBody({Key? key}) : super(key: key); @override State createState() => MapUiBodyState(); @@ -34,28 +35,28 @@ class MapUiBody extends StatefulWidget { class MapUiBodyState extends State { MapUiBodyState(); - static final CameraPosition _kInitialPosition = const CameraPosition( + static const CameraPosition _kInitialPosition = CameraPosition( target: LatLng(-33.852, 151.211), zoom: 11.0, ); CameraPosition _position = _kInitialPosition; bool _isMapCreated = false; - bool _isMoving = false; - bool _compassEnabled = true; - bool _mapToolbarEnabled = true; + final bool _isMoving = false; + final bool _compassEnabled = true; + final bool _mapToolbarEnabled = true; CameraTargetBounds _cameraTargetBounds = CameraTargetBounds.unbounded; MinMaxZoomPreference _minMaxZoomPreference = MinMaxZoomPreference.unbounded; MapType _mapType = MapType.normal; - bool _rotateGesturesEnabled = true; + final bool _rotateGesturesEnabled = true; bool _scrollGesturesEnabled = true; - bool _tiltGesturesEnabled = true; + final bool _tiltGesturesEnabled = true; bool _zoomControlsEnabled = false; bool _zoomGesturesEnabled = true; - bool _indoorViewEnabled = true; - bool _myLocationEnabled = true; + final bool _indoorViewEnabled = true; + final bool _myLocationEnabled = true; bool _myTrafficEnabled = false; - bool _myLocationButtonEnabled = true; + final bool _myLocationButtonEnabled = true; late GoogleMapController _controller; bool _nightMode = false; diff --git a/packages/google_maps_flutter/example/lib/marker_icons.dart b/packages/google_maps_flutter/example/lib/marker_icons.dart index da57b83a7..58d266c95 100644 --- a/packages/google_maps_flutter/example/lib/marker_icons.dart +++ b/packages/google_maps_flutter/example/lib/marker_icons.dart @@ -11,7 +11,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; class MarkerIconsPage extends GoogleMapExampleAppPage { - MarkerIconsPage() : super(const Icon(Icons.image), 'Marker icons'); + const MarkerIconsPage({Key? key}) + : super(const Icon(Icons.image), 'Marker icons', key: key); @override Widget build(BuildContext context) { @@ -20,7 +21,7 @@ class MarkerIconsPage extends GoogleMapExampleAppPage { } class MarkerIconsBody extends StatefulWidget { - const MarkerIconsBody(); + const MarkerIconsBody({Key? key}) : super(key: key); @override State createState() => MarkerIconsBodyState(); @@ -60,13 +61,13 @@ class MarkerIconsBodyState extends State { Marker _createMarker() { if (_markerIcon != null) { return Marker( - markerId: MarkerId("marker_1"), + markerId: const MarkerId('marker_1'), position: _kMapCenter, icon: _markerIcon!, ); } else { - return Marker( - markerId: MarkerId("marker_1"), + return const Marker( + markerId: MarkerId('marker_1'), position: _kMapCenter, ); } @@ -75,7 +76,7 @@ class MarkerIconsBodyState extends State { Future _createMarkerImageFromAsset(BuildContext context) async { if (_markerIcon == null) { final ImageConfiguration imageConfiguration = - createLocalImageConfiguration(context, size: Size.square(48)); + createLocalImageConfiguration(context, size: const Size.square(48)); BitmapDescriptor.fromAssetImage( imageConfiguration, 'assets/red_square.png') .then(_updateBitmap); diff --git a/packages/google_maps_flutter/example/lib/move_camera.dart b/packages/google_maps_flutter/example/lib/move_camera.dart index f82741967..7fa8a0354 100644 --- a/packages/google_maps_flutter/example/lib/move_camera.dart +++ b/packages/google_maps_flutter/example/lib/move_camera.dart @@ -10,7 +10,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; class MoveCameraPage extends GoogleMapExampleAppPage { - MoveCameraPage() : super(const Icon(Icons.map), 'Camera control'); + const MoveCameraPage({Key? key}) + : super(const Icon(Icons.map), 'Camera control', key: key); @override Widget build(BuildContext context) { @@ -19,7 +20,7 @@ class MoveCameraPage extends GoogleMapExampleAppPage { } class MoveCamera extends StatefulWidget { - const MoveCamera(); + const MoveCamera({Key? key}) : super(key: key); @override State createState() => MoveCameraState(); } @@ -27,6 +28,7 @@ class MoveCamera extends StatefulWidget { class MoveCameraState extends State { GoogleMapController? mapController; + // ignore: use_setters_to_change_properties void _onMapCreated(GoogleMapController controller) { mapController = controller; } diff --git a/packages/google_maps_flutter/example/lib/padding.dart b/packages/google_maps_flutter/example/lib/padding.dart index d90005fa6..a4bfa88d5 100644 --- a/packages/google_maps_flutter/example/lib/padding.dart +++ b/packages/google_maps_flutter/example/lib/padding.dart @@ -9,7 +9,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; class PaddingPage extends GoogleMapExampleAppPage { - PaddingPage() : super(const Icon(Icons.map), 'Add padding to the map'); + const PaddingPage({Key? key}) + : super(const Icon(Icons.map), 'Add padding to the map', key: key); @override Widget build(BuildContext context) { @@ -18,7 +19,7 @@ class PaddingPage extends GoogleMapExampleAppPage { } class MarkerIconsBody extends StatefulWidget { - const MarkerIconsBody(); + const MarkerIconsBody({Key? key}) : super(key: key); @override State createState() => MarkerIconsBodyState(); @@ -53,11 +54,11 @@ class MarkerIconsBodyState extends State { ), ), ), - Padding( - padding: const EdgeInsets.only(top: 20), + const Padding( + padding: EdgeInsets.only(top: 20), child: Center( child: Text( - "Enter Padding Below", + 'Enter Padding Below', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), ), @@ -79,10 +80,10 @@ class MarkerIconsBodyState extends State { }); } - TextEditingController _topController = TextEditingController(); - TextEditingController _bottomController = TextEditingController(); - TextEditingController _leftController = TextEditingController(); - TextEditingController _rightController = TextEditingController(); + final TextEditingController _topController = TextEditingController(); + final TextEditingController _bottomController = TextEditingController(); + final TextEditingController _leftController = TextEditingController(); + final TextEditingController _rightController = TextEditingController(); Widget _paddingInput() { return Padding( @@ -96,7 +97,7 @@ class MarkerIconsBodyState extends State { keyboardType: TextInputType.number, textAlign: TextAlign.center, decoration: const InputDecoration( - hintText: "Top", + hintText: 'Top', ), ), ), @@ -108,7 +109,7 @@ class MarkerIconsBodyState extends State { keyboardType: TextInputType.number, textAlign: TextAlign.center, decoration: const InputDecoration( - hintText: "Bottom", + hintText: 'Bottom', ), ), ), @@ -120,7 +121,7 @@ class MarkerIconsBodyState extends State { keyboardType: TextInputType.number, textAlign: TextAlign.center, decoration: const InputDecoration( - hintText: "Left", + hintText: 'Left', ), ), ), @@ -132,7 +133,7 @@ class MarkerIconsBodyState extends State { keyboardType: TextInputType.number, textAlign: TextAlign.center, decoration: const InputDecoration( - hintText: "Right", + hintText: 'Right', ), ), ), @@ -148,7 +149,7 @@ class MarkerIconsBodyState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ TextButton( - child: const Text("Set Padding"), + child: const Text('Set Padding'), onPressed: () { setState(() { _padding = EdgeInsets.fromLTRB( @@ -160,7 +161,7 @@ class MarkerIconsBodyState extends State { }, ), TextButton( - child: const Text("Reset Padding"), + child: const Text('Reset Padding'), onPressed: () { setState(() { _topController.clear(); diff --git a/packages/google_maps_flutter/example/lib/page.dart b/packages/google_maps_flutter/example/lib/page.dart index fb6eb3260..eb01ab07a 100644 --- a/packages/google_maps_flutter/example/lib/page.dart +++ b/packages/google_maps_flutter/example/lib/page.dart @@ -7,7 +7,8 @@ import 'package:flutter/material.dart'; abstract class GoogleMapExampleAppPage extends StatelessWidget { - const GoogleMapExampleAppPage(this.leading, this.title); + const GoogleMapExampleAppPage(this.leading, this.title, {Key? key}) + : super(key: key); final Widget leading; final String title; diff --git a/packages/google_maps_flutter/example/lib/place_circle.dart b/packages/google_maps_flutter/example/lib/place_circle.dart index a4953428f..7cbb63ac4 100644 --- a/packages/google_maps_flutter/example/lib/place_circle.dart +++ b/packages/google_maps_flutter/example/lib/place_circle.dart @@ -10,7 +10,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; class PlaceCirclePage extends GoogleMapExampleAppPage { - PlaceCirclePage() : super(const Icon(Icons.linear_scale), 'Place circle'); + const PlaceCirclePage({Key? key}) + : super(const Icon(Icons.linear_scale), 'Place circle', key: key); @override Widget build(BuildContext context) { @@ -19,7 +20,7 @@ class PlaceCirclePage extends GoogleMapExampleAppPage { } class PlaceCircleBody extends StatefulWidget { - const PlaceCircleBody(); + const PlaceCircleBody({Key? key}) : super(key: key); @override State createState() => PlaceCircleBodyState(); @@ -47,6 +48,7 @@ class PlaceCircleBodyState extends State { int widthsIndex = 0; List widths = [10, 20, 5]; + // ignore: use_setters_to_change_properties void _onMapCreated(GoogleMapController controller) { this.controller = controller; } @@ -169,42 +171,42 @@ class PlaceCircleBodyState extends State { Column( children: [ TextButton( - child: const Text('add'), onPressed: _add, + child: const Text('add'), ), TextButton( - child: const Text('remove'), onPressed: (selectedId == null) ? null : () => _remove(selectedId), + child: const Text('remove'), ), TextButton( - child: const Text('toggle visible'), onPressed: (selectedId == null) ? null : () => _toggleVisible(selectedId), + child: const Text('toggle visible'), ), ], ), Column( children: [ TextButton( - child: const Text('change stroke width'), onPressed: (selectedId == null) ? null : () => _changeStrokeWidth(selectedId), + child: const Text('change stroke width'), ), TextButton( - child: const Text('change stroke color'), onPressed: (selectedId == null) ? null : () => _changeStrokeColor(selectedId), + child: const Text('change stroke color'), ), TextButton( - child: const Text('change fill color'), onPressed: (selectedId == null) ? null : () => _changeFillColor(selectedId), + child: const Text('change fill color'), ), ], ) diff --git a/packages/google_maps_flutter/example/lib/place_marker.dart b/packages/google_maps_flutter/example/lib/place_marker.dart index 36ca60793..7935fd383 100644 --- a/packages/google_maps_flutter/example/lib/place_marker.dart +++ b/packages/google_maps_flutter/example/lib/place_marker.dart @@ -13,7 +13,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; class PlaceMarkerPage extends GoogleMapExampleAppPage { - PlaceMarkerPage() : super(const Icon(Icons.place), 'Place marker'); + const PlaceMarkerPage({Key? key}) + : super(const Icon(Icons.place), 'Place marker', key: key); @override Widget build(BuildContext context) { @@ -22,23 +23,25 @@ class PlaceMarkerPage extends GoogleMapExampleAppPage { } class PlaceMarkerBody extends StatefulWidget { - const PlaceMarkerBody(); + const PlaceMarkerBody({Key? key}) : super(key: key); @override State createState() => PlaceMarkerBodyState(); } -typedef Marker MarkerUpdateAction(Marker marker); +typedef MarkerUpdateAction = Marker Function(Marker marker); class PlaceMarkerBodyState extends State { PlaceMarkerBodyState(); - static final LatLng center = const LatLng(-33.86711, 151.1947171); + static const LatLng center = LatLng(-33.86711, 151.1947171); GoogleMapController? controller; Map markers = {}; MarkerId? selectedMarker; int _markerIdCounter = 1; + LatLng? markerPosition; + // ignore: use_setters_to_change_properties void _onMapCreated(GoogleMapController controller) { this.controller = controller; } @@ -65,13 +68,24 @@ class PlaceMarkerBodyState extends State { ), ); markers[markerId] = newMarker; + + markerPosition = null; }); } } - void _onMarkerDragEnd(MarkerId markerId, LatLng newPosition) async { + Future _onMarkerDrag(MarkerId markerId, LatLng newPosition) async { + setState(() { + markerPosition = newPosition; + }); + } + + Future _onMarkerDragEnd(MarkerId markerId, LatLng newPosition) async { final Marker? tappedMarker = markers[markerId]; if (tappedMarker != null) { + setState(() { + markerPosition = null; + }); await showDialog( context: context, builder: (BuildContext context) { @@ -113,12 +127,9 @@ class PlaceMarkerBodyState extends State { center.longitude + cos(_markerIdCounter * pi / 6.0) / 20.0, ), infoWindow: InfoWindow(title: markerIdVal, snippet: '*'), - onTap: () { - _onMarkerTapped(markerId); - }, - onDragEnd: (LatLng position) { - _onMarkerDragEnd(markerId, position); - }, + onTap: () => _onMarkerTapped(markerId), + onDragEnd: (LatLng position) => _onMarkerDragEnd(markerId, position), + onDrag: (LatLng position) => _onMarkerDrag(markerId, position), ); setState(() { @@ -151,31 +162,33 @@ class PlaceMarkerBodyState extends State { }); } - Future _changeInfoAnchor(MarkerId markerId) async { + void _changeAnchor(MarkerId markerId) { final Marker marker = markers[markerId]!; - final Offset currentAnchor = marker.infoWindow.anchor; + final Offset currentAnchor = marker.anchor; final Offset newAnchor = Offset(1.0 - currentAnchor.dy, currentAnchor.dx); setState(() { markers[markerId] = marker.copyWith( - infoWindowParam: marker.infoWindow.copyWith( - anchorParam: newAnchor, - ), + anchorParam: newAnchor, ); }); } - Future _toggleDraggable(MarkerId markerId) async { + Future _changeInfoAnchor(MarkerId markerId) async { final Marker marker = markers[markerId]!; + final Offset currentAnchor = marker.infoWindow.anchor; + final Offset newAnchor = Offset(1.0 - currentAnchor.dy, currentAnchor.dx); setState(() { markers[markerId] = marker.copyWith( - draggableParam: !marker.draggable, + infoWindowParam: marker.infoWindow.copyWith( + anchorParam: newAnchor, + ), ); }); } Future _changeInfo(MarkerId markerId) async { final Marker marker = markers[markerId]!; - final String newSnippet = marker.infoWindow.snippet! + '*'; + final String newSnippet = '${marker.infoWindow.snippet!}*'; setState(() { markers[markerId] = marker.copyWith( infoWindowParam: marker.infoWindow.copyWith( @@ -214,54 +227,15 @@ class PlaceMarkerBodyState extends State { }); } -// A breaking change to the ImageStreamListener API affects this sample. -// I've updates the sample to use the new API, but as we cannot use the new -// API before it makes it to stable I'm commenting out this sample for now -// TODO(amirh): uncomment this one the ImageStream API change makes it to stable. -// https://github.com/flutter/flutter/issues/33438 -// -// void _setMarkerIcon(BitmapDescriptor assetIcon) { -// if (selectedMarker == null) { -// return; -// } -// -// final Marker marker = markers[selectedMarker]; -// setState(() { -// markers[selectedMarker] = marker.copyWith( -// iconParam: assetIcon, -// ); -// }); -// } -// -// Future _getAssetIcon(BuildContext context) async { -// final Completer bitmapIcon = -// Completer(); -// final ImageConfiguration config = createLocalImageConfiguration(context); -// -// const AssetImage('assets/red_square.png') -// .resolve(config) -// .addListener(ImageStreamListener((ImageInfo image, bool sync) async { -// final ByteData bytes = -// await image.image.toByteData(format: ImageByteFormat.png); -// final BitmapDescriptor bitmap = -// BitmapDescriptor.fromBytes(bytes.buffer.asUint8List()); -// bitmapIcon.complete(bitmap); -// })); -// -// return await bitmapIcon.future; -// } - @override Widget build(BuildContext context) { final MarkerId? selectedId = selectedMarker; - return Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Center( - child: SizedBox( - width: 300.0, - height: 200.0, + return Stack(children: [ + Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Expanded( child: GoogleMap( onMapCreated: _onMapCreated, initialCameraPosition: const CameraPosition( @@ -271,97 +245,87 @@ class PlaceMarkerBodyState extends State { markers: Set.of(markers.values), ), ), - ), - Expanded( - child: SingleChildScrollView( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Row( - children: [ - Column( - children: [ - TextButton( - child: const Text('add'), - onPressed: _add, - ), - TextButton( - child: const Text('remove'), - onPressed: selectedId == null - ? null - : () => _remove(selectedId), - ), - TextButton( - child: const Text('change info'), - onPressed: selectedId == null - ? null - : () => _changeInfo(selectedId), - ), - TextButton( - child: const Text('change info anchor'), - onPressed: selectedId == null - ? null - : () => _changeInfoAnchor(selectedId), - ), - ], - ), - Column( - children: [ - TextButton( - child: const Text('change alpha'), - onPressed: selectedId == null - ? null - : () => _changeAlpha(selectedId), - ), - TextButton( - child: const Text('toggle draggable'), - onPressed: selectedId == null - ? null - : () => _toggleDraggable(selectedId), - ), - TextButton( - child: const Text('change position'), - onPressed: selectedId == null - ? null - : () => _changePosition(selectedId), - ), - TextButton( - child: const Text('toggle visible'), - onPressed: selectedId == null - ? null - : () => _toggleVisible(selectedId), - ), - TextButton( - child: const Text('change zIndex'), - onPressed: selectedId == null - ? null - : () => _changeZIndex(selectedId), - ), - // A breaking change to the ImageStreamListener API affects this sample. - // I've updates the sample to use the new API, but as we cannot use the new - // API before it makes it to stable I'm commenting out this sample for now - // TODO(amirh): uncomment this one the ImageStream API change makes it to stable. - // https://github.com/flutter/flutter/issues/33438 - // - // TextButton( - // child: const Text('set marker icon'), - // onPressed: () { - // _getAssetIcon(context).then( - // (BitmapDescriptor icon) { - // _setMarkerIcon(icon); - // }, - // ); - // }, - // ), - ], - ), - ], - ) - ], - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + TextButton( + onPressed: _add, + child: const Text('Add'), + ), + TextButton( + onPressed: + selectedId == null ? null : () => _remove(selectedId), + child: const Text('Remove'), + ), + ], + ), + Wrap( + alignment: WrapAlignment.spaceEvenly, + children: [ + TextButton( + onPressed: + selectedId == null ? null : () => _changeInfo(selectedId), + child: const Text('change info'), + ), + TextButton( + onPressed: selectedId == null + ? null + : () => _changeInfoAnchor(selectedId), + child: const Text('change info anchor'), + ), + TextButton( + onPressed: + selectedId == null ? null : () => _changeAlpha(selectedId), + child: const Text('change alpha'), + ), + TextButton( + onPressed: + selectedId == null ? null : () => _changeAnchor(selectedId), + child: const Text('change anchor'), + ), + TextButton( + onPressed: selectedId == null + ? null + : () => _changePosition(selectedId), + child: const Text('change position'), + ), + TextButton( + onPressed: selectedId == null + ? null + : () => _toggleVisible(selectedId), + child: const Text('toggle visible'), + ), + TextButton( + onPressed: + selectedId == null ? null : () => _changeZIndex(selectedId), + child: const Text('change zIndex'), + ), + ], + ), + ], + ), + Visibility( + visible: markerPosition != null, + child: Container( + color: Colors.white70, + height: 30, + padding: const EdgeInsets.only(left: 12, right: 12), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + mainAxisSize: MainAxisSize.max, + children: [ + if (markerPosition == null) + Container() + else + Expanded(child: Text('lat: ${markerPosition!.latitude}')), + if (markerPosition == null) + Container() + else + Expanded(child: Text('lng: ${markerPosition!.longitude}')), + ], ), ), - ], - ); + ), + ]); } } diff --git a/packages/google_maps_flutter/example/lib/place_polygon.dart b/packages/google_maps_flutter/example/lib/place_polygon.dart index 476084def..cb0cc56d4 100644 --- a/packages/google_maps_flutter/example/lib/place_polygon.dart +++ b/packages/google_maps_flutter/example/lib/place_polygon.dart @@ -10,7 +10,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; class PlacePolygonPage extends GoogleMapExampleAppPage { - PlacePolygonPage() : super(const Icon(Icons.linear_scale), 'Place polygon'); + const PlacePolygonPage({Key? key}) + : super(const Icon(Icons.linear_scale), 'Place polygon', key: key); @override Widget build(BuildContext context) { @@ -19,7 +20,7 @@ class PlacePolygonPage extends GoogleMapExampleAppPage { } class PlacePolygonBody extends StatefulWidget { - const PlacePolygonBody(); + const PlacePolygonBody({Key? key}) : super(key: key); @override State createState() => PlacePolygonBodyState(); @@ -48,6 +49,7 @@ class PlacePolygonBodyState extends State { int widthsIndex = 0; List widths = [10, 20, 5]; + // ignore: use_setters_to_change_properties void _onMapCreated(GoogleMapController controller) { this.controller = controller; } @@ -195,64 +197,64 @@ class PlacePolygonBodyState extends State { Column( children: [ TextButton( - child: const Text('add'), onPressed: _add, + child: const Text('add'), ), TextButton( - child: const Text('remove'), onPressed: (selectedId == null) ? null : () => _remove(selectedId), + child: const Text('remove'), ), TextButton( - child: const Text('toggle visible'), onPressed: (selectedId == null) ? null : () => _toggleVisible(selectedId), + child: const Text('toggle visible'), ), TextButton( - child: const Text('toggle geodesic'), onPressed: (selectedId == null) ? null : () => _toggleGeodesic(selectedId), + child: const Text('toggle geodesic'), ), ], ), Column( children: [ TextButton( - child: const Text('add holes'), onPressed: (selectedId == null) ? null : ((polygons[selectedId]!.holes.isNotEmpty) ? null : () => _addHoles(selectedId)), + child: const Text('add holes'), ), TextButton( - child: const Text('remove holes'), onPressed: (selectedId == null) ? null : ((polygons[selectedId]!.holes.isEmpty) ? null : () => _removeHoles(selectedId)), + child: const Text('remove holes'), ), TextButton( - child: const Text('change stroke width'), onPressed: (selectedId == null) ? null : () => _changeWidth(selectedId), + child: const Text('change stroke width'), ), TextButton( - child: const Text('change stroke color'), onPressed: (selectedId == null) ? null : () => _changeStrokeColor(selectedId), + child: const Text('change stroke color'), ), TextButton( - child: const Text('change fill color'), onPressed: (selectedId == null) ? null : () => _changeFillColor(selectedId), + child: const Text('change fill color'), ), ], ) diff --git a/packages/google_maps_flutter/example/lib/place_polyline.dart b/packages/google_maps_flutter/example/lib/place_polyline.dart index aeb9bf1b1..8b8ae3f27 100644 --- a/packages/google_maps_flutter/example/lib/place_polyline.dart +++ b/packages/google_maps_flutter/example/lib/place_polyline.dart @@ -4,14 +4,14 @@ // ignore_for_file: public_member_api_docs -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; class PlacePolylinePage extends GoogleMapExampleAppPage { - PlacePolylinePage() : super(const Icon(Icons.linear_scale), 'Place polyline'); + const PlacePolylinePage({Key? key}) + : super(const Icon(Icons.linear_scale), 'Place polyline', key: key); @override Widget build(BuildContext context) { @@ -20,7 +20,7 @@ class PlacePolylinePage extends GoogleMapExampleAppPage { } class PlacePolylineBody extends StatefulWidget { - const PlacePolylineBody(); + const PlacePolylineBody({Key? key}) : super(key: key); @override State createState() => PlacePolylineBodyState(); @@ -76,6 +76,7 @@ class PlacePolylineBodyState extends State { [PatternItem.dot, PatternItem.gap(10.0)], ]; + // ignore: use_setters_to_change_properties void _onMapCreated(GoogleMapController controller) { this.controller = controller; } @@ -163,46 +164,8 @@ class PlacePolylineBodyState extends State { }); } - void _changeJointType(PolylineId polylineId) { - final Polyline polyline = polylines[polylineId]!; - setState(() { - polylines[polylineId] = polyline.copyWith( - jointTypeParam: jointTypes[++jointTypesIndex % jointTypes.length], - ); - }); - } - - void _changeEndCap(PolylineId polylineId) { - final Polyline polyline = polylines[polylineId]!; - setState(() { - polylines[polylineId] = polyline.copyWith( - endCapParam: endCaps[++endCapsIndex % endCaps.length], - ); - }); - } - - void _changeStartCap(PolylineId polylineId) { - final Polyline polyline = polylines[polylineId]!; - setState(() { - polylines[polylineId] = polyline.copyWith( - startCapParam: startCaps[++startCapsIndex % startCaps.length], - ); - }); - } - - void _changePattern(PolylineId polylineId) { - final Polyline polyline = polylines[polylineId]!; - setState(() { - polylines[polylineId] = polyline.copyWith( - patternsParam: patterns[++patternsIndex % patterns.length], - ); - }); - } - @override Widget build(BuildContext context) { - final bool isIOS = !kIsWeb && defaultTargetPlatform == TargetPlatform.iOS; - final PolylineId? selectedId = selectedPolyline; return Column( @@ -233,66 +196,42 @@ class PlacePolylineBodyState extends State { Column( children: [ TextButton( - child: const Text('add'), onPressed: _add, + child: const Text('add'), ), TextButton( - child: const Text('remove'), onPressed: (selectedId == null) ? null : () => _remove(selectedId), + child: const Text('remove'), ), TextButton( - child: const Text('toggle visible'), onPressed: (selectedId == null) ? null : () => _toggleVisible(selectedId), + child: const Text('toggle visible'), ), TextButton( - child: const Text('toggle geodesic'), onPressed: (selectedId == null) ? null : () => _toggleGeodesic(selectedId), + child: const Text('toggle geodesic'), ), ], ), Column( children: [ TextButton( - child: const Text('change width'), onPressed: (selectedId == null) ? null : () => _changeWidth(selectedId), + child: const Text('change width'), ), TextButton( - child: const Text('change color'), onPressed: (selectedId == null) ? null : () => _changeColor(selectedId), - ), - TextButton( - child: const Text('change start cap [Android only]'), - onPressed: isIOS || (selectedId == null) - ? null - : () => _changeStartCap(selectedId), - ), - TextButton( - child: const Text('change end cap [Android only]'), - onPressed: isIOS || (selectedId == null) - ? null - : () => _changeEndCap(selectedId), - ), - TextButton( - child: const Text('change joint type [Android only]'), - onPressed: isIOS || (selectedId == null) - ? null - : () => _changeJointType(selectedId), - ), - TextButton( - child: const Text('change pattern [Android only]'), - onPressed: isIOS || (selectedId == null) - ? null - : () => _changePattern(selectedId), + child: const Text('change color'), ), ], ) diff --git a/packages/google_maps_flutter/example/lib/scrolling_map.dart b/packages/google_maps_flutter/example/lib/scrolling_map.dart index baed31830..3d676e071 100644 --- a/packages/google_maps_flutter/example/lib/scrolling_map.dart +++ b/packages/google_maps_flutter/example/lib/scrolling_map.dart @@ -11,8 +11,11 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; +const LatLng _center = LatLng(32.080664, 34.9563837); + class ScrollingMapPage extends GoogleMapExampleAppPage { - ScrollingMapPage() : super(const Icon(Icons.map), 'Scrolling map'); + const ScrollingMapPage({Key? key}) + : super(const Icon(Icons.map), 'Scrolling map', key: key); @override Widget build(BuildContext context) { @@ -21,9 +24,7 @@ class ScrollingMapPage extends GoogleMapExampleAppPage { } class ScrollingMapBody extends StatelessWidget { - const ScrollingMapBody(); - - final LatLng center = const LatLng(32.080664, 34.9563837); + const ScrollingMapBody({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -43,8 +44,8 @@ class ScrollingMapBody extends StatelessWidget { width: 300.0, height: 300.0, child: GoogleMap( - initialCameraPosition: CameraPosition( - target: center, + initialCameraPosition: const CameraPosition( + target: _center, zoom: 11.0, ), gestureRecognizers: // @@ -65,7 +66,7 @@ class ScrollingMapBody extends StatelessWidget { padding: const EdgeInsets.symmetric(vertical: 30.0), child: Column( children: [ - const Text('This map doesn\'t consume the vertical drags.'), + const Text("This map doesn't consume the vertical drags."), const Padding( padding: EdgeInsets.only(bottom: 12.0), child: @@ -76,16 +77,16 @@ class ScrollingMapBody extends StatelessWidget { width: 300.0, height: 300.0, child: GoogleMap( - initialCameraPosition: CameraPosition( - target: center, + initialCameraPosition: const CameraPosition( + target: _center, zoom: 11.0, ), markers: { Marker( - markerId: MarkerId("test_marker_id"), + markerId: const MarkerId('test_marker_id'), position: LatLng( - center.latitude, - center.longitude, + _center.latitude, + _center.longitude, ), infoWindow: const InfoWindow( title: 'An interesting location', diff --git a/packages/google_maps_flutter/example/lib/snapshot.dart b/packages/google_maps_flutter/example/lib/snapshot.dart index c85048f5b..fbc7ae2a3 100644 --- a/packages/google_maps_flutter/example/lib/snapshot.dart +++ b/packages/google_maps_flutter/example/lib/snapshot.dart @@ -15,8 +15,9 @@ const CameraPosition _kInitialPosition = CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0); class SnapshotPage extends GoogleMapExampleAppPage { - SnapshotPage() - : super(const Icon(Icons.camera_alt), 'Take a snapshot of the map'); + const SnapshotPage({Key? key}) + : super(const Icon(Icons.camera_alt), 'Take a snapshot of the map', + key: key); @override Widget build(BuildContext context) { @@ -39,7 +40,7 @@ class _SnapshotBodyState extends State<_SnapshotBody> { padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ + children: [ SizedBox( height: 180, child: GoogleMap( @@ -48,9 +49,10 @@ class _SnapshotBodyState extends State<_SnapshotBody> { ), ), TextButton( - child: Text('Take a snapshot'), + child: const Text('Take a snapshot'), onPressed: () async { - final imageBytes = await _mapController?.takeSnapshot(); + final Uint8List? imageBytes = + await _mapController?.takeSnapshot(); setState(() { _imageBytes = imageBytes; }); @@ -66,6 +68,7 @@ class _SnapshotBodyState extends State<_SnapshotBody> { ); } + // ignore: use_setters_to_change_properties void onMapCreated(GoogleMapController controller) { _mapController = controller; } diff --git a/packages/google_maps_flutter/example/lib/tile_overlay.dart b/packages/google_maps_flutter/example/lib/tile_overlay.dart index 1d6dd69c1..d88e09988 100644 --- a/packages/google_maps_flutter/example/lib/tile_overlay.dart +++ b/packages/google_maps_flutter/example/lib/tile_overlay.dart @@ -13,7 +13,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'page.dart'; class TileOverlayPage extends GoogleMapExampleAppPage { - TileOverlayPage() : super(const Icon(Icons.map), 'Tile overlay'); + const TileOverlayPage({Key? key}) + : super(const Icon(Icons.map), 'Tile overlay', key: key); @override Widget build(BuildContext context) { @@ -22,7 +23,7 @@ class TileOverlayPage extends GoogleMapExampleAppPage { } class TileOverlayBody extends StatefulWidget { - const TileOverlayBody(); + const TileOverlayBody({Key? key}) : super(key: key); @override State createState() => TileOverlayBodyState(); @@ -34,6 +35,7 @@ class TileOverlayBodyState extends State { GoogleMapController? controller; TileOverlay? _tileOverlay; + // ignore: use_setters_to_change_properties void _onMapCreated(GoogleMapController controller) { this.controller = controller; } @@ -51,7 +53,7 @@ class TileOverlayBodyState extends State { void _addTileOverlay() { final TileOverlay tileOverlay = TileOverlay( - tileOverlayId: TileOverlayId('tile_overlay_1'), + tileOverlayId: const TileOverlayId('tile_overlay_1'), tileProvider: _DebugTileProvider(), ); setState(() { @@ -67,7 +69,7 @@ class TileOverlayBodyState extends State { @override Widget build(BuildContext context) { - Set overlays = { + final Set overlays = { if (_tileOverlay != null) _tileOverlay!, }; return Column( @@ -90,16 +92,16 @@ class TileOverlayBodyState extends State { ), ), TextButton( - child: const Text('Add tile overlay'), onPressed: _addTileOverlay, + child: const Text('Add tile overlay'), ), TextButton( - child: const Text('Remove tile overlay'), onPressed: _removeTileOverlay, + child: const Text('Remove tile overlay'), ), TextButton( - child: const Text('Clear tile cache'), onPressed: _clearTileCache, + child: const Text('Clear tile cache'), ), ], ); @@ -117,7 +119,7 @@ class _DebugTileProvider implements TileProvider { static const int width = 100; static const int height = 100; static final Paint boxPaint = Paint(); - static final TextStyle textStyle = TextStyle( + static const TextStyle textStyle = TextStyle( color: Colors.red, fontSize: 20, ); @@ -138,7 +140,7 @@ class _DebugTileProvider implements TileProvider { minWidth: 0.0, maxWidth: width.toDouble(), ); - final Offset offset = const Offset(0, 0); + const Offset offset = Offset(0, 0); textPainter.paint(canvas, offset); canvas.drawRect( Rect.fromLTRB(0, 0, width.toDouble(), width.toDouble()), boxPaint); diff --git a/packages/google_maps_flutter/example/tizen/tizen-manifest.xml b/packages/google_maps_flutter/example/tizen/tizen-manifest.xml index 66a6db3ee..e6caf643c 100644 --- a/packages/google_maps_flutter/example/tizen/tizen-manifest.xml +++ b/packages/google_maps_flutter/example/tizen/tizen-manifest.xml @@ -1,6 +1,6 @@ - + ic_launcher.png diff --git a/packages/google_maps_flutter/lib/google_maps_flutter_tizen.dart b/packages/google_maps_flutter/lib/google_maps_flutter_tizen.dart index 4c5329b61..fd9137b99 100644 --- a/packages/google_maps_flutter/lib/google_maps_flutter_tizen.dart +++ b/packages/google_maps_flutter/lib/google_maps_flutter_tizen.dart @@ -10,28 +10,26 @@ import 'dart:convert'; import 'dart:io'; import 'dart:ui' as ui; -import 'package:flutter/widgets.dart'; -import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; import 'package:flutter/gestures.dart'; - -import 'package:stream_transform/stream_transform.dart'; - +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:stream_transform/stream_transform.dart'; import 'package:webview_flutter/webview_flutter.dart'; import 'src/util.dart' as util; -part 'src/google_maps_flutter_tizen.dart'; -part 'src/google_maps_controller.dart'; part 'src/circle.dart'; part 'src/circles.dart'; +part 'src/convert.dart'; +part 'src/google_maps_controller.dart'; +part 'src/google_maps_flutter_tizen.dart'; +part 'src/marker.dart'; +part 'src/markers.dart'; part 'src/polygon.dart'; part 'src/polygons.dart'; part 'src/polyline.dart'; part 'src/polylines.dart'; -part 'src/marker.dart'; -part 'src/markers.dart'; -part 'src/convert.dart'; part 'src/types.dart'; diff --git a/packages/google_maps_flutter/lib/src/convert.dart b/packages/google_maps_flutter/lib/src/convert.dart index 5c17d1c28..1efca64a3 100644 --- a/packages/google_maps_flutter/lib/src/convert.dart +++ b/packages/google_maps_flutter/lib/src/convert.dart @@ -116,7 +116,7 @@ final Set _mapStyleKeys = { }; // Checks if the passed in Map contains some of the _mapStyleKeys. -bool _isJsonMapStyle(Map value) { +bool _isJsonMapStyle(Map value) { return _mapStyleKeys.intersection(value.keys.toSet()).isNotEmpty; } @@ -136,12 +136,13 @@ String _mapStyles(String? mapStyleJson) { if (mapStyleJson != null) { try { json - .decode(mapStyleJson, reviver: (key, value) { - if (value is Map && _isJsonMapStyle(value)) { + .decode(mapStyleJson, reviver: (Object? key, Object? value) { + if (value is Map && + _isJsonMapStyle(value as Map)) { return MapTypeStyle() ..elementType = value['elementType'] as String? ..featureType = value['featureType'] as String? - ..stylers = (value['stylers'] as List) + ..stylers = (value['stylers']! as List) .map((dynamic e) => e) .toList(); } @@ -232,7 +233,7 @@ util.GInfoWindowOptions? _infoWindowOptionsFromMarker(Marker marker) { buffer.write(markerSnippet); buffer.write(''); } - buffer.write('\''); + buffer.write("'"); // Need to add Click Event to infoWindow's content return util.GInfoWindowOptions() @@ -247,7 +248,7 @@ util.GMarkerOptions _markerOptionsFromMarker( Marker marker, util.GMarker? currentMarker, ) { - final iconConfig = marker.icon.toJson() as List; + final List iconConfig = marker.icon.toJson() as List; util.GIcon? icon; if (iconConfig.isNotEmpty) { @@ -259,8 +260,9 @@ util.GMarkerOptions _markerOptionsFromMarker( // iconConfig[3] may contain the [width, height] of the image, if passed! if (iconConfig.length >= 4 && iconConfig[3] != null) { + final List rawIconSize = iconConfig[3]! as List; final util.GSize size = - util.GSize(iconConfig[3][0] as num, iconConfig[3][1] as num); + util.GSize(rawIconSize[0] as num?, rawIconSize[1] as num?); icon ..size = size ..scaledSize = size; @@ -291,7 +293,7 @@ util.GMarkerOptions _markerOptionsFromMarker( // Converts a [Color] into a valid CSS value #RRGGBB. String _getCssColor(Color color) { - return '#' + color.value.toRadixString(16).padLeft(8, '0').substring(2); + return '#${color.value.toRadixString(16).padLeft(8, '0').substring(2)}'; } // Extracts the opacity from a [Color]. @@ -315,10 +317,11 @@ util.GPolylineOptions _polylineOptionsFromPolyline(Polyline polyline) { util.GPolygonOptions _polygonOptionsFromPolygon(Polygon polygon) { final List path = polygon.points; final bool polygonDirection = _isPolygonClockwise(path); - final List> paths = [path]; + final List> paths = >[path]; int holeIndex = 0; - polygon.holes.forEach((List hole) { - List holePath = hole; + + for (int i = 0; i < polygon.holes.length; i++) { + List holePath = polygon.holes[i]; if (_isPolygonClockwise(holePath) == polygonDirection) { holePath = holePath.reversed.toList(); if (kDebugMode) { @@ -330,7 +333,8 @@ util.GPolygonOptions _polygonOptionsFromPolygon(Polygon polygon) { } paths.add(holePath); holeIndex++; - }); + } + return util.GPolygonOptions() ..paths = paths ..strokeColor = _getCssColor(polygon.strokeColor) diff --git a/packages/google_maps_flutter/lib/src/google_maps_controller.dart b/packages/google_maps_flutter/lib/src/google_maps_controller.dart index 4054e96bc..329278625 100644 --- a/packages/google_maps_flutter/lib/src/google_maps_controller.dart +++ b/packages/google_maps_flutter/lib/src/google_maps_controller.dart @@ -7,6 +7,30 @@ part of google_maps_flutter_tizen; /// This class implements a Map Controller and its events class GoogleMapsController { + /// Initializes the GoogleMapsController. + GoogleMapsController({ + required int mapId, + required StreamController> streamController, + required CameraPosition initialCameraPosition, + Set markers = const {}, + Set polygons = const {}, + Set polylines = const {}, + Set circles = const {}, + Map mapOptions = const {}, + }) : _mapId = mapId, + _streamController = streamController, + _initialCameraPosition = initialCameraPosition, + _markers = markers, + _polygons = polygons, + _polylines = polylines, + _circles = circles, + _rawMapOptions = mapOptions { + _circlesController = CirclesController(stream: _streamController); + _polygonsController = PolygonsController(stream: _streamController); + _polylinesController = PolylinesController(stream: _streamController); + _markersController = MarkersController(stream: _streamController); + } + // The internal ID of the map. Used to broadcast events, DOM IDs and everything where a unique ID is needed. final int _mapId; @@ -158,30 +182,6 @@ class GoogleMapsController { // Keeps track if the map is moving or not. bool _mapIsMoving = false; - /// Initializes the GoogleMapsController. - GoogleMapsController({ - required int mapId, - required StreamController> streamController, - required CameraPosition initialCameraPosition, - Set markers = const {}, - Set polygons = const {}, - Set polylines = const {}, - Set circles = const {}, - Map mapOptions = const {}, - }) : _mapId = mapId, - _streamController = streamController, - _initialCameraPosition = initialCameraPosition, - _markers = markers, - _polygons = polygons, - _polylines = polylines, - _circles = circles, - _rawMapOptions = mapOptions { - _circlesController = CirclesController(stream: _streamController); - _polygonsController = PolygonsController(stream: _streamController); - _polylinesController = PolylinesController(stream: _streamController); - _markersController = MarkersController(stream: _streamController); - } - JavascriptChannel _onBoundsChanged() { return JavascriptChannel( name: 'BoundChanged', @@ -490,12 +490,12 @@ class GoogleMapsController { Future _setOptions(String options) async { if (_controller.isCompleted) { - await _callMethod(await controller, 'setOptions', [options]); + await _callMethod(await controller, 'setOptions', [options]); } } Future _setZoom(String options) async { - await _callMethod(await controller, 'setZoom', [options]); + await _callMethod(await controller, 'setZoom', [options]); } // Attaches/detaches a Traffic Layer on the `map` if `attach` is true/false. @@ -517,19 +517,19 @@ class GoogleMapsController { } Future _setMoveCamera(String options) async { - await _callMethod(await controller, 'moveCamera', [options]); + await _callMethod(await controller, 'moveCamera', [options]); } Future _setPanTo(String options) async { - await _callMethod(await controller, 'panTo', [options]); + await _callMethod(await controller, 'panTo', [options]); } Future _setPanBy(String options) async { - await _callMethod(await controller, 'panBy', [options]); + await _callMethod(await controller, 'panBy', [options]); } Future _setFitBounds(String options) async { - await _callMethod(await controller, 'fitBounds', [options]); + await _callMethod(await controller, 'fitBounds', [options]); } Future _callMethod( @@ -540,7 +540,7 @@ class GoogleMapsController { Future _getZoom(WebViewController c) async { try { - return double.parse(await _callMethod(c, 'getZoom', [])); + return double.parse(await _callMethod(c, 'getZoom', [])); } catch (e) { print('Javascript Error: $e'); return 0.0; @@ -550,13 +550,13 @@ class GoogleMapsController { /// Returns the [LatLngBounds] of the current viewport. Future getVisibleRegion() async { return _convertToBounds( - await _callMethod(await controller, 'getBounds', [])); + await _callMethod(await controller, 'getBounds', [])); } /// Returns the [LatLng] at the center of the map. Future getCenter() async { return _convertToLatLng( - await _callMethod(await controller, 'getCenter', [])); + await _callMethod(await controller, 'getCenter', [])); } /// Returns the [ScreenCoordinate] for a given viewport [LatLng]. @@ -614,7 +614,7 @@ class GoogleMapsController { focusLatLng = await _pixelToLatLng( json[2][0] as double, json[2][1] as double); } catch (e) { - print('Error computing focus LatLng. JS Error: ' + e.toString()); + print('Error computing focus LatLng. JS Error: ${e.toString()}'); } } await _setZoom('${(await getZoomLevel()) + newZoomDelta}'); diff --git a/packages/google_maps_flutter/lib/src/marker.dart b/packages/google_maps_flutter/lib/src/marker.dart index de7dcc046..ca4a1e789 100644 --- a/packages/google_maps_flutter/lib/src/marker.dart +++ b/packages/google_maps_flutter/lib/src/marker.dart @@ -41,8 +41,8 @@ class MarkerController { LatLngCallback? dragEndEvent; Future _addMarkerEvent(Future? _controller) async { - final String command = - '''$marker.addListener("click", (event) => MarkerClick.postMessage(JSON.stringify(${marker?.id}))); + final String command = ''' + $marker.addListener("click", (event) => MarkerClick.postMessage(JSON.stringify(${marker?.id}))); $marker.addListener("dragend", (event) => MarkerDragEnd.postMessage(JSON.stringify({id:${marker?.id}, event:event})));'''; await (await _controller!).runJavascript(command); } diff --git a/packages/google_maps_flutter/lib/src/markers.dart b/packages/google_maps_flutter/lib/src/markers.dart index c6c394d9f..1c14a87bf 100644 --- a/packages/google_maps_flutter/lib/src/markers.dart +++ b/packages/google_maps_flutter/lib/src/markers.dart @@ -9,7 +9,7 @@ part of google_maps_flutter_tizen; class MarkersController extends GeometryController { /// Initialize the cache. The [StreamController] comes from the [GoogleMapController], and is shared with other controllers. MarkersController({ - required StreamController stream, + required StreamController> stream, }) : _streamController = stream, _idToMarkerId = {}, _markerIdToController = {}; @@ -19,7 +19,7 @@ class MarkersController extends GeometryController { final Map _idToMarkerId; // The stream over which markers broadcast their events - final StreamController _streamController; + final StreamController> _streamController; /// Adds a set of [Marker] objects to the cache. /// @@ -142,8 +142,10 @@ class MarkersController extends GeometryController { void _hideAllMarkerInfoWindow() { _markerIdToController.values - .where((controller) => - controller == null ? false : controller.infoWindowShown) - .forEach((controller) => controller.hideInfoWindow()); + .where((MarkerController? controller) => + controller?.infoWindowShown ?? false) + .forEach((MarkerController controller) { + controller.hideInfoWindow(); + }); } } diff --git a/packages/google_maps_flutter/lib/src/polygons.dart b/packages/google_maps_flutter/lib/src/polygons.dart index 8902f126b..7412156bb 100644 --- a/packages/google_maps_flutter/lib/src/polygons.dart +++ b/packages/google_maps_flutter/lib/src/polygons.dart @@ -9,7 +9,7 @@ part of google_maps_flutter_tizen; class PolygonsController extends GeometryController { /// Initializes the cache. The [StreamController] comes from the [GoogleMapController], and is shared with other controllers. PolygonsController({ - required StreamController stream, + required StreamController> stream, }) : _streamController = stream, _polygonIdToController = {}, _idToPolygonId = {}; @@ -19,7 +19,7 @@ class PolygonsController extends GeometryController { final Map _idToPolygonId; // The stream over which polygons broadcast events - final StreamController _streamController; + final StreamController> _streamController; /// Adds a set of [Polygon] objects to the cache. /// diff --git a/packages/google_maps_flutter/lib/src/util.dart b/packages/google_maps_flutter/lib/src/util.dart index 44d483f01..cffa9eca7 100644 --- a/packages/google_maps_flutter/lib/src/util.dart +++ b/packages/google_maps_flutter/lib/src/util.dart @@ -3,6 +3,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ignore_for_file: avoid_setters_without_getters + //part of google_maps_flutter_tizen; import 'dart:async'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; @@ -198,7 +200,7 @@ class GInfoWindow { set pixelOffset(GSize? size) => _setPixelOffset(size); void _setContent(Object? /*String?|Node?*/ content) { - callMethod(this, 'setContent', [content]); + callMethod(this, 'setContent', [content]); } void _setPixelOffset(GSize? size) { @@ -247,15 +249,15 @@ class GMarker { } Future _setMap(Object? /*GMap?|StreetViewPanorama?*/ map) async { - await callMethod(this, 'setMap', [map]); + await callMethod(this, 'setMap', [map]); } Future _setOptions(GMarkerOptions? options) async { - await callMethod(this, 'setOptions', [options]); + await callMethod(this, 'setOptions', [options]); } Future _setVisible(bool? visible) async { - await callMethod(this, 'setVisible', [visible]); + await callMethod(this, 'setVisible', [visible]); } } @@ -294,15 +296,15 @@ class GPolyline { } Future _setVisible(bool? visible) async { - await callMethod(this, 'setVisible', [visible]); + await callMethod(this, 'setVisible', [visible]); } Future _setMap(Object? /*GMap?|StreetViewPanorama?*/ map) async { - await callMethod(this, 'setMap', [map]); + await callMethod(this, 'setMap', [map]); } Future _setOptions(GPolylineOptions? options) async { - await callMethod(this, 'setOptions', [options]); + await callMethod(this, 'setOptions', [options]); } } @@ -388,15 +390,15 @@ class GPolygon { } Future _setVisible(bool? visible) async { - await callMethod(this, 'setVisible', [visible]); + await callMethod(this, 'setVisible', [visible]); } Future _setMap(Object? /*GMap?|StreetViewPanorama?*/ map) async { - await callMethod(this, 'setMap', [map]); + await callMethod(this, 'setMap', [map]); } Future _setOptions(GPolygonOptions? options) async { - await callMethod(this, 'setOptions', [options]); + await callMethod(this, 'setOptions', [options]); } } @@ -495,19 +497,19 @@ class GCircle { } Future _setVisible(bool? visible) async { - await callMethod(this, 'setVisible', [visible]); + await callMethod(this, 'setVisible', [visible]); } Future _setRadius(num? radius) async { - await callMethod(this, 'setRadius', [radius]); + await callMethod(this, 'setRadius', [radius]); } Future _setMap(Object? /*GMap?|StreetViewPanorama?*/ map) async { - await callMethod(this, 'setMap', [map]); + await callMethod(this, 'setMap', [map]); } Future _setOptions(GCircleOptions? options) async { - await callMethod(this, 'setOptions', [options]); + await callMethod(this, 'setOptions', [options]); } } @@ -561,7 +563,7 @@ Future? webController; /// Returns the property value of the object. Future getProperty(Object o, String property) async { assert(webController != null, 'mapController is null!!'); - final String command = 'JSON.stringify(${o.toString()}[\'$property\'])'; + final String command = "JSON.stringify(${o.toString()}['$property'])"; return await (await webController!).runJavascriptReturningResult(command); } @@ -569,7 +571,7 @@ Future getProperty(Object o, String property) async { Future setProperty(Object o, String property, Object? value) async { assert(webController != null, 'mapController is null!!'); final String command = - 'JSON.stringify(${o.toString()}[\'$property\'] = $value)'; + "JSON.stringify(${o.toString()}['$property'] = $value)"; return await (await webController!).runJavascriptReturningResult(command); } From 5bd319ed6ea54d4fc6c123812a3a54b63e702fcb Mon Sep 17 00:00:00 2001 From: Seungsoo Lee Date: Mon, 13 Jun 2022 18:23:35 +0900 Subject: [PATCH 3/3] Fix minor bugs Signed-off-by: Seungsoo Lee --- packages/google_maps_flutter/CHANGELOG.md | 2 ++ packages/google_maps_flutter/README.md | 4 ++-- packages/google_maps_flutter/example/assets/map.html | 2 +- packages/google_maps_flutter/pubspec.yaml | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/google_maps_flutter/CHANGELOG.md b/packages/google_maps_flutter/CHANGELOG.md index e193de987..9c7937f4b 100644 --- a/packages/google_maps_flutter/CHANGELOG.md +++ b/packages/google_maps_flutter/CHANGELOG.md @@ -1,6 +1,8 @@ ## 0.1.2 * Fix variouse bugs. +* Update webview_flutter to 3.0.4. +* Update webview_flutter_tizen to 0.5.1. ## 0.1.1 diff --git a/packages/google_maps_flutter/README.md b/packages/google_maps_flutter/README.md index 736cd2d86..e54d4c8e2 100644 --- a/packages/google_maps_flutter/README.md +++ b/packages/google_maps_flutter/README.md @@ -20,8 +20,8 @@ This package is not an _endorsed_ implementation of `google_maps_flutter`. There ```yaml dependencies: - google_maps_flutter: ^2.0.8 - google_maps_flutter_tizen: ^0.1.1 + google_maps_flutter: ^2.1.7 + google_maps_flutter_tizen: ^0.1.2 ``` In addition, you need a Maps JavaScript API Key to use this plugin. Please refer to the site below to get the API key. diff --git a/packages/google_maps_flutter/example/assets/map.html b/packages/google_maps_flutter/example/assets/map.html index a76fa7472..0bad0c96a 100644 --- a/packages/google_maps_flutter/example/assets/map.html +++ b/packages/google_maps_flutter/example/assets/map.html @@ -18,7 +18,7 @@ let map; console.log("before load"); - diff --git a/packages/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/pubspec.yaml index 682910de3..5e7bed4bd 100644 --- a/packages/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: meta: ^1.3.0 stream_transform: ^2.0.0 webview_flutter: ^3.0.4 - webview_flutter_tizen: ^0.5.0 + webview_flutter_tizen: ^0.5.1 dev_dependencies: flutter_test: