From 06c54b04d9699a66a984f88da3ab709799463fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4limaa?= Date: Tue, 10 Dec 2024 15:02:55 +0800 Subject: [PATCH] refactor: general pr improvements --- .../maps/flutter/navigation/GoogleMapView.kt | 2 +- .../navigation/GoogleMapsNavigationView.kt | 2 +- .../maps/flutter/navigation/ConvertTest.kt | 30 +++---------- example/lib/pages/navigation.dart | 44 +++++++++---------- example/lib/pages/widget_initialization.dart | 4 +- .../MapConfiguration.swift | 4 +- lib/src/google_maps_auto_view_controller.dart | 5 ++- lib/src/google_maps_map_view.dart | 2 +- lib/src/google_maps_map_view_controller.dart | 4 +- ...navigation_flutter_platform_interface.dart | 4 +- .../method_channel/common_auto_view_api.dart | 11 ++--- lib/src/method_channel/common_view_api.dart | 19 +++++--- lib/src/method_channel/convert/convert.dart | 1 - .../method_channel/convert/map_padding.dart | 25 ----------- lib/src/types/navigation_view_types.dart | 16 ------- .../types/view_initialization_options.dart | 4 +- 16 files changed, 65 insertions(+), 112 deletions(-) delete mode 100644 lib/src/method_channel/convert/map_padding.dart diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapView.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapView.kt index 1e9a297..557b9f9 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapView.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapView.kt @@ -48,8 +48,8 @@ internal constructor( initListeners() imageRegistry.mapViewInitializationComplete() mapReady() - invalidateViewAfterMapLoad() mapOptions.padding?.let { setPadding(it) } + invalidateViewAfterMapLoad() } viewRegistry.registerMapView(viewId, this) diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsNavigationView.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsNavigationView.kt index a0f095f..e6de2ef 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsNavigationView.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsNavigationView.kt @@ -81,8 +81,8 @@ internal constructor( // Call and clear view ready callback if available. mapReady() - invalidateViewAfterMapLoad() mapOptions.padding?.let { setPadding(it) } + invalidateViewAfterMapLoad() } viewRegistry.registerNavigationView(viewId, this) diff --git a/android/src/test/kotlin/com/google/maps/flutter/navigation/ConvertTest.kt b/android/src/test/kotlin/com/google/maps/flutter/navigation/ConvertTest.kt index 64d88cf..16e6083 100644 --- a/android/src/test/kotlin/com/google/maps/flutter/navigation/ConvertTest.kt +++ b/android/src/test/kotlin/com/google/maps/flutter/navigation/ConvertTest.kt @@ -376,20 +376,11 @@ internal class ConvertTest { val mapOptions = Convert.convertMapOptionsFromDto(testOptions) - assertEquals( - mapOptions.googleMapOptions.camera.target.latitude, - testOptions.cameraPosition.target.latitude, - ) + assertEquals(mapOptions.googleMapOptions.camera.target.latitude, testOptions.cameraPosition.target.latitude) - assertEquals( - mapOptions.googleMapOptions.camera.target.longitude, - testOptions.cameraPosition.target.longitude, - ) + assertEquals(mapOptions.googleMapOptions.camera.target.longitude, testOptions.cameraPosition.target.longitude) - assertEquals( - mapOptions.googleMapOptions.camera.bearing, - testOptions.cameraPosition.bearing.toFloat(), - ) + assertEquals(mapOptions.googleMapOptions.camera.bearing, testOptions.cameraPosition.bearing.toFloat()) assertEquals(mapOptions.googleMapOptions.camera.tilt, testOptions.cameraPosition.tilt.toFloat()) @@ -399,10 +390,7 @@ internal class ConvertTest { assertEquals(mapOptions.googleMapOptions.compassEnabled, testOptions.compassEnabled) - assertEquals( - mapOptions.googleMapOptions.scrollGesturesEnabled, - testOptions.scrollGesturesEnabled, - ) + assertEquals(mapOptions.googleMapOptions.scrollGesturesEnabled, testOptions.scrollGesturesEnabled) assertEquals(mapOptions.googleMapOptions.tiltGesturesEnabled, testOptions.tiltGesturesEnabled) @@ -435,15 +423,9 @@ internal class ConvertTest { testOptions.cameraTargetBounds?.southwest?.longitude, ) - assertEquals( - mapOptions.googleMapOptions.minZoomPreference, - testOptions.minZoomPreference?.toFloat(), - ) + assertEquals(mapOptions.googleMapOptions.minZoomPreference, testOptions.minZoomPreference?.toFloat()) - assertEquals( - mapOptions.googleMapOptions.maxZoomPreference, - testOptions.maxZoomPreference?.toFloat(), - ) + assertEquals(mapOptions.googleMapOptions.maxZoomPreference, testOptions.maxZoomPreference?.toFloat()) assertEquals(mapOptions.googleMapOptions.zoomControlsEnabled, testOptions.zoomControlsEnabled) diff --git a/example/lib/pages/navigation.dart b/example/lib/pages/navigation.dart index 936738c..825d273 100644 --- a/example/lib/pages/navigation.dart +++ b/example/lib/pages/navigation.dart @@ -142,9 +142,8 @@ class _NavigationPageState extends ExamplePageState { int _nextWaypointIndex = 0; - MapPadding _mapPadding = MapPadding(top: 0, left: 0, bottom: 0, right: 0); - MapPadding _autoViewMapPadding = - MapPadding(top: 0, left: 0, bottom: 0, right: 0); + EdgeInsets _mapPadding = const EdgeInsets.all(0); + EdgeInsets _autoViewMapPadding = const EdgeInsets.all(0); @override void initState() { @@ -979,7 +978,7 @@ class _NavigationPageState extends ExamplePageState { 'Current route segment destination: ${segment?.destinationWaypoint?.title ?? 'unknown'}'); } - Future _setPadding(MapPadding padding) async { + Future _setPadding(EdgeInsets padding) async { try { await _navigationViewController!.setPadding(padding); setState(() { @@ -990,7 +989,7 @@ class _NavigationPageState extends ExamplePageState { } } - Future _setAutoViewPadding(MapPadding padding) async { + Future _setAutoViewPadding(EdgeInsets padding) async { try { await _autoViewController.setPadding(padding); setState(() { @@ -1029,8 +1028,7 @@ class _NavigationPageState extends ExamplePageState { initialNavigationUIEnabledPreference: _guidanceRunning ? NavigationUIEnabledPreference.automatic : NavigationUIEnabledPreference.disabled, - initialPadding: - MapPadding(top: 0, left: 0, bottom: 0, right: 0)) + initialPadding: const EdgeInsets.all(0)) : const Center( child: Column( mainAxisSize: MainAxisSize.min, @@ -1511,9 +1509,9 @@ class _NavigationPageState extends ExamplePageState { divisions: 20, label: _mapPadding.left.toString(), onChanged: (double value) { - _setPadding(MapPadding( + _setPadding(EdgeInsets.only( top: _mapPadding.top, - left: value.round(), + left: value, bottom: _mapPadding.bottom, right: _mapPadding.right)); }), @@ -1525,11 +1523,11 @@ class _NavigationPageState extends ExamplePageState { divisions: 20, label: _mapPadding.right.toString(), onChanged: (double value) { - _setPadding(MapPadding( + _setPadding(EdgeInsets.only( top: _mapPadding.top, left: _mapPadding.left, bottom: _mapPadding.bottom, - right: value.round())); + right: value)); }), Text('Map top padding: ${_mapPadding.top}'), Slider( @@ -1539,8 +1537,8 @@ class _NavigationPageState extends ExamplePageState { divisions: 20, label: _mapPadding.top.toString(), onChanged: (double value) { - _setPadding(MapPadding( - top: value.round(), + _setPadding(EdgeInsets.only( + top: value, left: _mapPadding.left, bottom: _mapPadding.bottom, right: _mapPadding.right)); @@ -1553,10 +1551,10 @@ class _NavigationPageState extends ExamplePageState { divisions: 20, label: _mapPadding.bottom.toString(), onChanged: (double value) { - _setPadding(MapPadding( + _setPadding(EdgeInsets.only( top: _mapPadding.top, left: _mapPadding.left, - bottom: value.round(), + bottom: value, right: _mapPadding.right)); }), ]), @@ -1590,9 +1588,9 @@ class _NavigationPageState extends ExamplePageState { divisions: 20, label: _autoViewMapPadding.left.toString(), onChanged: (double value) { - _setAutoViewPadding(MapPadding( + _setAutoViewPadding(EdgeInsets.only( top: _autoViewMapPadding.top, - left: value.round(), + left: value, bottom: _autoViewMapPadding.bottom, right: _autoViewMapPadding.right)); }), @@ -1604,11 +1602,11 @@ class _NavigationPageState extends ExamplePageState { divisions: 20, label: _autoViewMapPadding.right.toString(), onChanged: (double value) { - _setAutoViewPadding(MapPadding( + _setAutoViewPadding(EdgeInsets.only( top: _autoViewMapPadding.top, left: _autoViewMapPadding.left, bottom: _autoViewMapPadding.bottom, - right: value.round())); + right: value)); }), Text('Map top padding: ${_autoViewMapPadding.top}'), Slider( @@ -1618,8 +1616,8 @@ class _NavigationPageState extends ExamplePageState { divisions: 20, label: _autoViewMapPadding.top.toString(), onChanged: (double value) { - _setAutoViewPadding(MapPadding( - top: value.round(), + _setAutoViewPadding(EdgeInsets.only( + top: value, left: _autoViewMapPadding.left, bottom: _autoViewMapPadding.bottom, right: _autoViewMapPadding.right)); @@ -1632,10 +1630,10 @@ class _NavigationPageState extends ExamplePageState { divisions: 20, label: _autoViewMapPadding.bottom.toString(), onChanged: (double value) { - _setAutoViewPadding(MapPadding( + _setAutoViewPadding(EdgeInsets.only( top: _autoViewMapPadding.top, left: _autoViewMapPadding.left, - bottom: value.round(), + bottom: value, right: _autoViewMapPadding.right)); }), ]), diff --git a/example/lib/pages/widget_initialization.dart b/example/lib/pages/widget_initialization.dart index 3f1e2d8..9456390 100644 --- a/example/lib/pages/widget_initialization.dart +++ b/example/lib/pages/widget_initialization.dart @@ -49,7 +49,7 @@ class _ViewInitializationPageState double? _initialMaxZoomPreference; bool _initialZoomControlsEnabled = true; LatLngBounds? _initialCameraTargetBounds; - MapPadding? _initialPadding; + EdgeInsets? _initialPadding; NavigationUIEnabledPreference _initialNavigationUIEnabledPreference = NavigationUIEnabledPreference.automatic; TextDirection? _layoutDirection; @@ -425,7 +425,7 @@ class _InitializedViewPage extends StatelessWidget { final double? initialMaxZoomPreference; final bool initialZoomControlsEnabled; final LatLngBounds? initialCameraTargetBounds; - final MapPadding? initialPadding; + final EdgeInsets? initialPadding; final NavigationUIEnabledPreference initialNavigationUIEnabledPreference; @override diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/MapConfiguration.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/MapConfiguration.swift index bbc410a..80aa055 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/MapConfiguration.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/MapConfiguration.swift @@ -58,7 +58,9 @@ extension MapConfiguration { minZoomPreference ?? kGMSMinZoomLevel, maxZoom: maxZoomPreference ?? kGMSMaxZoomLevel ) - mapView.padding = padding ?? UIEdgeInsets.zero + if let padding { + mapView.padding = padding + } } // Applies the configuration to the given diff --git a/lib/src/google_maps_auto_view_controller.dart b/lib/src/google_maps_auto_view_controller.dart index cc5360c..d69cae1 100644 --- a/lib/src/google_maps_auto_view_controller.dart +++ b/lib/src/google_maps_auto_view_controller.dart @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:flutter/widgets.dart'; + import '../google_navigation_flutter.dart'; import 'google_navigation_flutter_platform_interface.dart'; @@ -325,7 +327,8 @@ class GoogleMapsAutoViewController { return GoogleMapsNavigationPlatform.instance.clearForAuto(); } - Future setPadding(MapPadding padding) { + /// Set padding for the map view. + Future setPadding(EdgeInsets padding) { return GoogleMapsNavigationPlatform.instance .setPaddingForAuto(padding: padding); } diff --git a/lib/src/google_maps_map_view.dart b/lib/src/google_maps_map_view.dart index a6114a2..61d2ca0 100644 --- a/lib/src/google_maps_map_view.dart +++ b/lib/src/google_maps_map_view.dart @@ -151,7 +151,7 @@ abstract class GoogleMapsBaseMapView extends StatefulWidget { /// Specifies the initial padding for the map view. /// /// Null by default (no padding). - final MapPadding? initialPadding; + final EdgeInsets? initialPadding; /// Which gestures should be forwarded to the PlatformView. /// diff --git a/lib/src/google_maps_map_view_controller.dart b/lib/src/google_maps_map_view_controller.dart index 6d640fb..187d93d 100644 --- a/lib/src/google_maps_map_view_controller.dart +++ b/lib/src/google_maps_map_view_controller.dart @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:flutter/widgets.dart'; + import '../google_navigation_flutter.dart'; import 'google_navigation_flutter_platform_interface.dart'; @@ -365,7 +367,7 @@ class GoogleMapViewController { } /// Set padding for the map view. - Future setPadding(MapPadding padding) { + Future setPadding(EdgeInsets padding) { return GoogleMapsNavigationPlatform.instance .setPadding(viewId: _viewId, padding: padding); } diff --git a/lib/src/google_navigation_flutter_platform_interface.dart b/lib/src/google_navigation_flutter_platform_interface.dart index 74a1298..c47d917 100644 --- a/lib/src/google_navigation_flutter_platform_interface.dart +++ b/lib/src/google_navigation_flutter_platform_interface.dart @@ -533,7 +533,7 @@ abstract mixin class MapViewAPIInterface { Future registerOnCameraChangedListener({required int viewId}); // Sets the map padding for the map view. - Future setPadding({required int viewId, required MapPadding padding}); + Future setPadding({required int viewId, required EdgeInsets padding}); /// Get navigation view marker event stream from the navigation view. Stream getMarkerEventStream({required int viewId}); @@ -773,7 +773,7 @@ abstract mixin class AutoMapViewAPIInterface { Future isAutoScreenAvailable(); // Sets the map padding for the auto map view. - Future setPaddingForAuto({required MapPadding padding}); + Future setPaddingForAuto({required EdgeInsets padding}); /// Get custom navigation auto event stream from the auto view. Stream getCustomNavigationAutoEventStream(); diff --git a/lib/src/method_channel/common_auto_view_api.dart b/lib/src/method_channel/common_auto_view_api.dart index bd31bca..9d5fb75 100644 --- a/lib/src/method_channel/common_auto_view_api.dart +++ b/lib/src/method_channel/common_auto_view_api.dart @@ -16,6 +16,7 @@ import 'dart:async'; import 'dart:io'; import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; import '../../google_navigation_flutter.dart'; import '../google_navigation_flutter_platform_interface.dart'; @@ -736,12 +737,12 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { } @override - Future setPaddingForAuto({required MapPadding padding}) { + Future setPaddingForAuto({required EdgeInsets padding}) { return _viewApi.setPadding(MapPaddingDto( - top: padding.top, - left: padding.left, - bottom: padding.bottom, - right: padding.right)); + top: padding.top.toInt(), + left: padding.left.toInt(), + bottom: padding.bottom.toInt(), + right: padding.right.toInt())); } @override diff --git a/lib/src/method_channel/common_view_api.dart b/lib/src/method_channel/common_view_api.dart index 3aa0f62..31149ef 100644 --- a/lib/src/method_channel/common_view_api.dart +++ b/lib/src/method_channel/common_view_api.dart @@ -16,6 +16,7 @@ import 'dart:async'; import 'dart:io'; import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; import '../../google_navigation_flutter.dart'; import '../google_navigation_flutter_platform_interface.dart'; @@ -107,7 +108,13 @@ mixin CommonMapViewAPI on MapViewAPIInterface { maxZoomPreference: mapOptions.maxZoomPreference, zoomControlsEnabled: mapOptions.zoomControlsEnabled, cameraTargetBounds: mapOptions.cameraTargetBounds?.toDto(), - padding: mapOptions.padding?.toDto()); + padding: mapOptions.padding != null + ? MapPaddingDto( + top: mapOptions.padding!.top.toInt(), + left: mapOptions.padding!.left.toInt(), + bottom: mapOptions.padding!.bottom.toInt(), + right: mapOptions.padding!.right.toInt()) + : null); // Initialize navigation view options if given NavigationViewOptionsDto? navigationOptionsMessage; @@ -937,14 +944,14 @@ mixin CommonMapViewAPI on MapViewAPIInterface { } @override - Future setPadding({required int viewId, required MapPadding padding}) { + Future setPadding({required int viewId, required EdgeInsets padding}) { return _viewApi.setPadding( viewId, MapPaddingDto( - top: padding.top, - left: padding.left, - bottom: padding.bottom, - right: padding.right)); + top: padding.top.toInt(), + left: padding.left.toInt(), + bottom: padding.bottom.toInt(), + right: padding.right.toInt())); } @override diff --git a/lib/src/method_channel/convert/convert.dart b/lib/src/method_channel/convert/convert.dart index 5c74e04..49590f7 100644 --- a/lib/src/method_channel/convert/convert.dart +++ b/lib/src/method_channel/convert/convert.dart @@ -19,7 +19,6 @@ export 'latlng.dart'; export 'latlng_bounds.dart'; export 'map_type.dart'; export 'marker.dart'; -export 'map_padding.dart'; export 'navigation.dart'; export 'navigation_display_options.dart'; export 'navigation_routing_options.dart'; diff --git a/lib/src/method_channel/convert/map_padding.dart b/lib/src/method_channel/convert/map_padding.dart deleted file mode 100644 index 767a654..0000000 --- a/lib/src/method_channel/convert/map_padding.dart +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import '../../types/types.dart'; -import '../method_channel.dart'; - -/// [MapPadding] convert extension. -/// @nodoc -extension ConvertMapPadding on MapPadding { - /// Convert [LatLngBounds] to [LatLngBoundsDto]. - MapPaddingDto toDto() { - return MapPaddingDto(top: top, left: left, bottom: bottom, right: right); - } -} diff --git a/lib/src/types/navigation_view_types.dart b/lib/src/types/navigation_view_types.dart index c4d47e9..e54e098 100644 --- a/lib/src/types/navigation_view_types.dart +++ b/lib/src/types/navigation_view_types.dart @@ -439,19 +439,3 @@ class CameraChangedEvent { /// Current position of the camera. final CameraPosition position; } - -/// Represent map padding for the Google Maps view. -/// {@category Navigation View} -/// {@category Map View} -class MapPadding { - MapPadding( - {required this.top, - required this.left, - required this.bottom, - required this.right}); - - final int top; - final int left; - final int bottom; - final int right; -} diff --git a/lib/src/types/view_initialization_options.dart b/lib/src/types/view_initialization_options.dart index a3fac44..83ccc73 100644 --- a/lib/src/types/view_initialization_options.dart +++ b/lib/src/types/view_initialization_options.dart @@ -11,10 +11,10 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -import 'dart:ui'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; +import 'package:flutter/widgets.dart'; import '../../google_navigation_flutter.dart'; @@ -188,7 +188,7 @@ class MapOptions { /// Specifies the initial padding for the map view. /// /// Null by default (no padding). - final MapPadding? padding; + final EdgeInsets? padding; } /// Determines the initial visibility of the navigation UI on map initialization.