Skip to content

Commit

Permalink
refactor: general pr improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
illuminati1911 committed Dec 10, 2024
1 parent a5432e3 commit deafcbb
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ internal constructor(
initListeners()
imageRegistry.mapViewInitializationComplete()
mapReady()
invalidateViewAfterMapLoad()
mapOptions.padding?.let { setPadding(it) }
invalidateViewAfterMapLoad()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ internal constructor(

// Call and clear view ready callback if available.
mapReady()
invalidateViewAfterMapLoad()
mapOptions.padding?.let { setPadding(it) }
invalidateViewAfterMapLoad()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
44 changes: 21 additions & 23 deletions example/lib/pages/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {

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() {
Expand Down Expand Up @@ -979,7 +978,7 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
'Current route segment destination: ${segment?.destinationWaypoint?.title ?? 'unknown'}');
}

Future<void> _setPadding(MapPadding padding) async {
Future<void> _setPadding(EdgeInsets padding) async {
try {
await _navigationViewController!.setPadding(padding);
setState(() {
Expand All @@ -990,7 +989,7 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
}
}

Future<void> _setAutoViewPadding(MapPadding padding) async {
Future<void> _setAutoViewPadding(EdgeInsets padding) async {
try {
await _autoViewController.setPadding(padding);
setState(() {
Expand Down Expand Up @@ -1029,8 +1028,7 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
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,
Expand Down Expand Up @@ -1511,9 +1509,9 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
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));
}),
Expand All @@ -1525,11 +1523,11 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
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(
Expand All @@ -1539,8 +1537,8 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
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));
Expand All @@ -1553,10 +1551,10 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
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));
}),
]),
Expand Down Expand Up @@ -1590,9 +1588,9 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
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));
}),
Expand All @@ -1604,11 +1602,11 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
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(
Expand All @@ -1618,8 +1616,8 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
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));
Expand All @@ -1632,10 +1630,10 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
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));
}),
]),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/widget_initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _ViewInitializationPageState
double? _initialMaxZoomPreference;
bool _initialZoomControlsEnabled = true;
LatLngBounds? _initialCameraTargetBounds;
MapPadding? _initialPadding;
EdgeInsets? _initialPadding;
NavigationUIEnabledPreference _initialNavigationUIEnabledPreference =
NavigationUIEnabledPreference.automatic;
TextDirection? _layoutDirection;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/src/google_maps_auto_view_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -325,7 +327,8 @@ class GoogleMapsAutoViewController {
return GoogleMapsNavigationPlatform.instance.clearForAuto();
}

Future<void> setPadding(MapPadding padding) {
/// Set padding for the map view.
Future<void> setPadding(EdgeInsets padding) {
return GoogleMapsNavigationPlatform.instance
.setPaddingForAuto(padding: padding);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/google_maps_map_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
4 changes: 3 additions & 1 deletion lib/src/google_maps_map_view_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -365,7 +367,7 @@ class GoogleMapViewController {
}

/// Set padding for the map view.
Future<void> setPadding(MapPadding padding) {
Future<void> setPadding(EdgeInsets padding) {
return GoogleMapsNavigationPlatform.instance
.setPadding(viewId: _viewId, padding: padding);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/google_navigation_flutter_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ abstract mixin class MapViewAPIInterface {
Future<void> registerOnCameraChangedListener({required int viewId});

// Sets the map padding for the map view.
Future<void> setPadding({required int viewId, required MapPadding padding});
Future<void> setPadding({required int viewId, required EdgeInsets padding});

/// Get navigation view marker event stream from the navigation view.
Stream<MarkerEvent> getMarkerEventStream({required int viewId});
Expand Down Expand Up @@ -773,7 +773,7 @@ abstract mixin class AutoMapViewAPIInterface {
Future<bool> isAutoScreenAvailable();

// Sets the map padding for the auto map view.
Future<void> setPaddingForAuto({required MapPadding padding});
Future<void> setPaddingForAuto({required EdgeInsets padding});

/// Get custom navigation auto event stream from the auto view.
Stream<CustomNavigationAutoEvent> getCustomNavigationAutoEventStream();
Expand Down
11 changes: 6 additions & 5 deletions lib/src/method_channel/common_auto_view_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -736,12 +737,12 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface {
}

@override
Future<void> setPaddingForAuto({required MapPadding padding}) {
Future<void> 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
Expand Down
19 changes: 13 additions & 6 deletions lib/src/method_channel/common_view_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -937,14 +944,14 @@ mixin CommonMapViewAPI on MapViewAPIInterface {
}

@override
Future<void> setPadding({required int viewId, required MapPadding padding}) {
Future<void> 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
Expand Down
1 change: 0 additions & 1 deletion lib/src/method_channel/convert/convert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading

0 comments on commit deafcbb

Please sign in to comment.