From f798d1bded1ea1e25576afadfbc1334ba602cb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4limaa?= Date: Fri, 6 Dec 2024 18:00:42 +0800 Subject: [PATCH 1/7] feat: add map padding support --- .../GoogleMapsAutoViewMessageHandler.kt | 4 + .../navigation/GoogleMapsBaseMapView.kt | 10 + .../GoogleMapsViewMessageHandler.kt | 4 + .../maps/flutter/navigation/messages.g.kt | 283 +++++++++++------ example/lib/pages/navigation.dart | 138 +++++++++ .../GoogleMapsAutoViewMessageHandler.swift | 4 + .../GoogleMapsNavigationView.swift | 9 + ...ogleMapsNavigationViewMessageHandler.swift | 4 + .../messages.g.swift | 289 ++++++++++++------ lib/src/google_maps_auto_view_controller.dart | 5 + lib/src/google_maps_map_view_controller.dart | 6 + ...navigation_flutter_platform_interface.dart | 6 + .../method_channel/common_auto_view_api.dart | 9 + lib/src/method_channel/common_view_api.dart | 11 + lib/src/method_channel/messages.g.dart | 289 ++++++++++++------ lib/src/types/navigation_view_types.dart | 16 + pigeons/messages.dart | 15 + test/messages_test.g.dart | 83 +++-- 18 files changed, 873 insertions(+), 312 deletions(-) diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoViewMessageHandler.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoViewMessageHandler.kt index 351a4fe..0cf191b 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoViewMessageHandler.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoViewMessageHandler.kt @@ -385,4 +385,8 @@ class GoogleMapsAutoViewMessageHandler(private val viewRegistry: GoogleMapsViewR override fun isAutoScreenAvailable(): Boolean { return viewRegistry.getAndroidAutoView() != null } + + override fun setPadding(padding: MapPaddingDto) { + getView().setPadding(padding) + } } diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt index 9223b98..75ce385 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt @@ -942,4 +942,14 @@ abstract class GoogleMapsBaseMapView( ) {} } } + + fun setPadding(padding: MapPaddingDto) { + getMap() + .setPadding( + padding.left.toInt(), + padding.top.toInt(), + padding.right.toInt(), + padding.bottom.toInt(), + ) + } } diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsViewMessageHandler.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsViewMessageHandler.kt index 2215a6f..98cab2b 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsViewMessageHandler.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsViewMessageHandler.kt @@ -475,4 +475,8 @@ class GoogleMapsViewMessageHandler(private val viewRegistry: GoogleMapsViewRegis override fun registerOnCameraChangedListener(viewId: Long) { getView(viewId.toInt()).registerOnCameraChangedListener() } + + override fun setPadding(viewId: Long, padding: MapPaddingDto) { + getView(viewId.toInt()).setPadding(padding) + } } diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt index 57ab185..108b12f 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt @@ -1103,6 +1103,25 @@ data class CircleOptionsDto( } } +/** Generated class from Pigeon that represents data sent in messages. */ +data class MapPaddingDto(val top: Long, val left: Long, val bottom: Long, val right: Long) { + + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): MapPaddingDto { + val top = list[0].let { if (it is Int) it.toLong() else it as Long } + val left = list[1].let { if (it is Int) it.toLong() else it as Long } + val bottom = list[2].let { if (it is Int) it.toLong() else it as Long } + val right = list[3].let { if (it is Int) it.toLong() else it as Long } + return MapPaddingDto(top, left, bottom, right) + } + } + + fun toList(): List { + return listOf(top, left, bottom, right) + } +} + /** Generated class from Pigeon that represents data sent in messages. */ data class RouteTokenOptionsDto(val routeToken: String, val travelMode: TravelModeDto? = null) { @@ -1825,36 +1844,39 @@ private object MapViewApiCodec : StandardMessageCodec() { return (readValue(buffer) as? List)?.let { LatLngDto.fromList(it) } } 136.toByte() -> { - return (readValue(buffer) as? List)?.let { MarkerAnchorDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MapPaddingDto.fromList(it) } } 137.toByte() -> { - return (readValue(buffer) as? List)?.let { MarkerDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MarkerAnchorDto.fromList(it) } } 138.toByte() -> { - return (readValue(buffer) as? List)?.let { MarkerOptionsDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MarkerDto.fromList(it) } } 139.toByte() -> { - return (readValue(buffer) as? List)?.let { PatternItemDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MarkerOptionsDto.fromList(it) } } 140.toByte() -> { - return (readValue(buffer) as? List)?.let { PolygonDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PatternItemDto.fromList(it) } } 141.toByte() -> { - return (readValue(buffer) as? List)?.let { PolygonHoleDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolygonDto.fromList(it) } } 142.toByte() -> { - return (readValue(buffer) as? List)?.let { PolygonOptionsDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolygonHoleDto.fromList(it) } } 143.toByte() -> { - return (readValue(buffer) as? List)?.let { PolylineDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolygonOptionsDto.fromList(it) } } 144.toByte() -> { - return (readValue(buffer) as? List)?.let { PolylineOptionsDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolylineDto.fromList(it) } } 145.toByte() -> { - return (readValue(buffer) as? List)?.let { StyleSpanDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolylineOptionsDto.fromList(it) } } 146.toByte() -> { + return (readValue(buffer) as? List)?.let { StyleSpanDto.fromList(it) } + } + 147.toByte() -> { return (readValue(buffer) as? List)?.let { StyleSpanStrokeStyleDto.fromList(it) } } else -> super.readValueOfType(type, buffer) @@ -1895,50 +1917,54 @@ private object MapViewApiCodec : StandardMessageCodec() { stream.write(135) writeValue(stream, value.toList()) } - is MarkerAnchorDto -> { + is MapPaddingDto -> { stream.write(136) writeValue(stream, value.toList()) } - is MarkerDto -> { + is MarkerAnchorDto -> { stream.write(137) writeValue(stream, value.toList()) } - is MarkerOptionsDto -> { + is MarkerDto -> { stream.write(138) writeValue(stream, value.toList()) } - is PatternItemDto -> { + is MarkerOptionsDto -> { stream.write(139) writeValue(stream, value.toList()) } - is PolygonDto -> { + is PatternItemDto -> { stream.write(140) writeValue(stream, value.toList()) } - is PolygonHoleDto -> { + is PolygonDto -> { stream.write(141) writeValue(stream, value.toList()) } - is PolygonOptionsDto -> { + is PolygonHoleDto -> { stream.write(142) writeValue(stream, value.toList()) } - is PolylineDto -> { + is PolygonOptionsDto -> { stream.write(143) writeValue(stream, value.toList()) } - is PolylineOptionsDto -> { + is PolylineDto -> { stream.write(144) writeValue(stream, value.toList()) } - is StyleSpanDto -> { + is PolylineOptionsDto -> { stream.write(145) writeValue(stream, value.toList()) } - is StyleSpanStrokeStyleDto -> { + is StyleSpanDto -> { stream.write(146) writeValue(stream, value.toList()) } + is StyleSpanStrokeStyleDto -> { + stream.write(147) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } @@ -2166,6 +2192,8 @@ interface MapViewApi { fun registerOnCameraChangedListener(viewId: Long) + fun setPadding(viewId: Long, padding: MapPaddingDto) + companion object { /** The codec used by MapViewApi. */ val codec: MessageCodec by lazy { MapViewApiCodec } @@ -4376,6 +4404,31 @@ interface MapViewApi { channel.setMessageHandler(null) } } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.google_navigation_flutter.MapViewApi.setPadding", + codec, + ) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val viewIdArg = args[0].let { if (it is Int) it.toLong() else it as Long } + val paddingArg = args[1] as MapPaddingDto + var wrapped: List + try { + api.setPadding(viewIdArg, paddingArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } } } } @@ -6119,36 +6172,39 @@ private object AutoMapViewApiCodec : StandardMessageCodec() { return (readValue(buffer) as? List)?.let { LatLngDto.fromList(it) } } 136.toByte() -> { - return (readValue(buffer) as? List)?.let { MarkerAnchorDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MapPaddingDto.fromList(it) } } 137.toByte() -> { - return (readValue(buffer) as? List)?.let { MarkerDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MarkerAnchorDto.fromList(it) } } 138.toByte() -> { - return (readValue(buffer) as? List)?.let { MarkerOptionsDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MarkerDto.fromList(it) } } 139.toByte() -> { - return (readValue(buffer) as? List)?.let { PatternItemDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MarkerOptionsDto.fromList(it) } } 140.toByte() -> { - return (readValue(buffer) as? List)?.let { PolygonDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PatternItemDto.fromList(it) } } 141.toByte() -> { - return (readValue(buffer) as? List)?.let { PolygonHoleDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolygonDto.fromList(it) } } 142.toByte() -> { - return (readValue(buffer) as? List)?.let { PolygonOptionsDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolygonHoleDto.fromList(it) } } 143.toByte() -> { - return (readValue(buffer) as? List)?.let { PolylineDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolygonOptionsDto.fromList(it) } } 144.toByte() -> { - return (readValue(buffer) as? List)?.let { PolylineOptionsDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolylineDto.fromList(it) } } 145.toByte() -> { - return (readValue(buffer) as? List)?.let { StyleSpanDto.fromList(it) } + return (readValue(buffer) as? List)?.let { PolylineOptionsDto.fromList(it) } } 146.toByte() -> { + return (readValue(buffer) as? List)?.let { StyleSpanDto.fromList(it) } + } + 147.toByte() -> { return (readValue(buffer) as? List)?.let { StyleSpanStrokeStyleDto.fromList(it) } } else -> super.readValueOfType(type, buffer) @@ -6189,50 +6245,54 @@ private object AutoMapViewApiCodec : StandardMessageCodec() { stream.write(135) writeValue(stream, value.toList()) } - is MarkerAnchorDto -> { + is MapPaddingDto -> { stream.write(136) writeValue(stream, value.toList()) } - is MarkerDto -> { + is MarkerAnchorDto -> { stream.write(137) writeValue(stream, value.toList()) } - is MarkerOptionsDto -> { + is MarkerDto -> { stream.write(138) writeValue(stream, value.toList()) } - is PatternItemDto -> { + is MarkerOptionsDto -> { stream.write(139) writeValue(stream, value.toList()) } - is PolygonDto -> { + is PatternItemDto -> { stream.write(140) writeValue(stream, value.toList()) } - is PolygonHoleDto -> { + is PolygonDto -> { stream.write(141) writeValue(stream, value.toList()) } - is PolygonOptionsDto -> { + is PolygonHoleDto -> { stream.write(142) writeValue(stream, value.toList()) } - is PolylineDto -> { + is PolygonOptionsDto -> { stream.write(143) writeValue(stream, value.toList()) } - is PolylineOptionsDto -> { + is PolylineDto -> { stream.write(144) writeValue(stream, value.toList()) } - is StyleSpanDto -> { + is PolylineOptionsDto -> { stream.write(145) writeValue(stream, value.toList()) } - is StyleSpanStrokeStyleDto -> { + is StyleSpanDto -> { stream.write(146) writeValue(stream, value.toList()) } + is StyleSpanStrokeStyleDto -> { + stream.write(147) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } @@ -6411,6 +6471,8 @@ interface AutoMapViewApi { fun isAutoScreenAvailable(): Boolean + fun setPadding(padding: MapPaddingDto) + companion object { /** The codec used by AutoMapViewApi. */ val codec: MessageCodec by lazy { AutoMapViewApiCodec } @@ -8109,6 +8171,30 @@ interface AutoMapViewApi { channel.setMessageHandler(null) } } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.google_navigation_flutter.AutoMapViewApi.setPadding", + codec, + ) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val paddingArg = args[0] as MapPaddingDto + var wrapped: List + try { + api.setPadding(paddingArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } } } } @@ -8151,88 +8237,91 @@ private object AutoViewEventApiCodec : StandardMessageCodec() { return (readValue(buffer) as? List)?.let { MapOptionsDto.fromList(it) } } 139.toByte() -> { - return (readValue(buffer) as? List)?.let { MarkerAnchorDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MapPaddingDto.fromList(it) } } 140.toByte() -> { - return (readValue(buffer) as? List)?.let { MarkerDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MarkerAnchorDto.fromList(it) } } 141.toByte() -> { - return (readValue(buffer) as? List)?.let { MarkerOptionsDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MarkerDto.fromList(it) } } 142.toByte() -> { - return (readValue(buffer) as? List)?.let { NavInfoDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MarkerOptionsDto.fromList(it) } } 143.toByte() -> { + return (readValue(buffer) as? List)?.let { NavInfoDto.fromList(it) } + } + 144.toByte() -> { return (readValue(buffer) as? List)?.let { NavigationAudioGuidanceSettingsDto.fromList(it) } } - 144.toByte() -> { + 145.toByte() -> { return (readValue(buffer) as? List)?.let { NavigationDisplayOptionsDto.fromList(it) } } - 145.toByte() -> { + 146.toByte() -> { return (readValue(buffer) as? List)?.let { NavigationTimeAndDistanceDto.fromList(it) } } - 146.toByte() -> { + 147.toByte() -> { return (readValue(buffer) as? List)?.let { NavigationViewOptionsDto.fromList(it) } } - 147.toByte() -> { + 148.toByte() -> { return (readValue(buffer) as? List)?.let { NavigationWaypointDto.fromList(it) } } - 148.toByte() -> { + 149.toByte() -> { return (readValue(buffer) as? List)?.let { PatternItemDto.fromList(it) } } - 149.toByte() -> { + 150.toByte() -> { return (readValue(buffer) as? List)?.let { PolygonDto.fromList(it) } } - 150.toByte() -> { + 151.toByte() -> { return (readValue(buffer) as? List)?.let { PolygonHoleDto.fromList(it) } } - 151.toByte() -> { + 152.toByte() -> { return (readValue(buffer) as? List)?.let { PolygonOptionsDto.fromList(it) } } - 152.toByte() -> { + 153.toByte() -> { return (readValue(buffer) as? List)?.let { PolylineDto.fromList(it) } } - 153.toByte() -> { + 154.toByte() -> { return (readValue(buffer) as? List)?.let { PolylineOptionsDto.fromList(it) } } - 154.toByte() -> { + 155.toByte() -> { return (readValue(buffer) as? List)?.let { RouteSegmentDto.fromList(it) } } - 155.toByte() -> { + 156.toByte() -> { return (readValue(buffer) as? List)?.let { RouteSegmentTrafficDataDto.fromList(it) } } - 156.toByte() -> { + 157.toByte() -> { return (readValue(buffer) as? List)?.let { RouteSegmentTrafficDataRoadStretchRenderingDataDto.fromList(it) } } - 157.toByte() -> { + 158.toByte() -> { return (readValue(buffer) as? List)?.let { RouteTokenOptionsDto.fromList(it) } } - 158.toByte() -> { + 159.toByte() -> { return (readValue(buffer) as? List)?.let { RoutingOptionsDto.fromList(it) } } - 159.toByte() -> { + 160.toByte() -> { return (readValue(buffer) as? List)?.let { SimulationOptionsDto.fromList(it) } } - 160.toByte() -> { + 161.toByte() -> { return (readValue(buffer) as? List)?.let { SpeedAlertOptionsDto.fromList(it) } } - 161.toByte() -> { + 162.toByte() -> { return (readValue(buffer) as? List)?.let { SpeedingUpdatedEventDto.fromList(it) } } - 162.toByte() -> { + 163.toByte() -> { return (readValue(buffer) as? List)?.let { StepInfoDto.fromList(it) } } - 163.toByte() -> { + 164.toByte() -> { return (readValue(buffer) as? List)?.let { StyleSpanDto.fromList(it) } } - 164.toByte() -> { + 165.toByte() -> { return (readValue(buffer) as? List)?.let { StyleSpanStrokeStyleDto.fromList(it) } } - 165.toByte() -> { + 166.toByte() -> { return (readValue(buffer) as? List)?.let { ViewCreationOptionsDto.fromList(it) } } else -> super.readValueOfType(type, buffer) @@ -8285,114 +8374,118 @@ private object AutoViewEventApiCodec : StandardMessageCodec() { stream.write(138) writeValue(stream, value.toList()) } - is MarkerAnchorDto -> { + is MapPaddingDto -> { stream.write(139) writeValue(stream, value.toList()) } - is MarkerDto -> { + is MarkerAnchorDto -> { stream.write(140) writeValue(stream, value.toList()) } - is MarkerOptionsDto -> { + is MarkerDto -> { stream.write(141) writeValue(stream, value.toList()) } - is NavInfoDto -> { + is MarkerOptionsDto -> { stream.write(142) writeValue(stream, value.toList()) } - is NavigationAudioGuidanceSettingsDto -> { + is NavInfoDto -> { stream.write(143) writeValue(stream, value.toList()) } - is NavigationDisplayOptionsDto -> { + is NavigationAudioGuidanceSettingsDto -> { stream.write(144) writeValue(stream, value.toList()) } - is NavigationTimeAndDistanceDto -> { + is NavigationDisplayOptionsDto -> { stream.write(145) writeValue(stream, value.toList()) } - is NavigationViewOptionsDto -> { + is NavigationTimeAndDistanceDto -> { stream.write(146) writeValue(stream, value.toList()) } - is NavigationWaypointDto -> { + is NavigationViewOptionsDto -> { stream.write(147) writeValue(stream, value.toList()) } - is PatternItemDto -> { + is NavigationWaypointDto -> { stream.write(148) writeValue(stream, value.toList()) } - is PolygonDto -> { + is PatternItemDto -> { stream.write(149) writeValue(stream, value.toList()) } - is PolygonHoleDto -> { + is PolygonDto -> { stream.write(150) writeValue(stream, value.toList()) } - is PolygonOptionsDto -> { + is PolygonHoleDto -> { stream.write(151) writeValue(stream, value.toList()) } - is PolylineDto -> { + is PolygonOptionsDto -> { stream.write(152) writeValue(stream, value.toList()) } - is PolylineOptionsDto -> { + is PolylineDto -> { stream.write(153) writeValue(stream, value.toList()) } - is RouteSegmentDto -> { + is PolylineOptionsDto -> { stream.write(154) writeValue(stream, value.toList()) } - is RouteSegmentTrafficDataDto -> { + is RouteSegmentDto -> { stream.write(155) writeValue(stream, value.toList()) } - is RouteSegmentTrafficDataRoadStretchRenderingDataDto -> { + is RouteSegmentTrafficDataDto -> { stream.write(156) writeValue(stream, value.toList()) } - is RouteTokenOptionsDto -> { + is RouteSegmentTrafficDataRoadStretchRenderingDataDto -> { stream.write(157) writeValue(stream, value.toList()) } - is RoutingOptionsDto -> { + is RouteTokenOptionsDto -> { stream.write(158) writeValue(stream, value.toList()) } - is SimulationOptionsDto -> { + is RoutingOptionsDto -> { stream.write(159) writeValue(stream, value.toList()) } - is SpeedAlertOptionsDto -> { + is SimulationOptionsDto -> { stream.write(160) writeValue(stream, value.toList()) } - is SpeedingUpdatedEventDto -> { + is SpeedAlertOptionsDto -> { stream.write(161) writeValue(stream, value.toList()) } - is StepInfoDto -> { + is SpeedingUpdatedEventDto -> { stream.write(162) writeValue(stream, value.toList()) } - is StyleSpanDto -> { + is StepInfoDto -> { stream.write(163) writeValue(stream, value.toList()) } - is StyleSpanStrokeStyleDto -> { + is StyleSpanDto -> { stream.write(164) writeValue(stream, value.toList()) } - is ViewCreationOptionsDto -> { + is StyleSpanStrokeStyleDto -> { stream.write(165) writeValue(stream, value.toList()) } + is ViewCreationOptionsDto -> { + stream.write(166) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } diff --git a/example/lib/pages/navigation.dart b/example/lib/pages/navigation.dart index 1058084..ba792c9 100644 --- a/example/lib/pages/navigation.dart +++ b/example/lib/pages/navigation.dart @@ -142,6 +142,10 @@ 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); + @override void initState() { super.initState(); @@ -975,6 +979,28 @@ class _NavigationPageState extends ExamplePageState { 'Current route segment destination: ${segment?.destinationWaypoint?.title ?? 'unknown'}'); } + Future _setPadding(MapPadding padding) async { + try { + await _navigationViewController!.setPadding(padding); + setState(() { + _mapPadding = padding; + }); + } catch (e) { + showMessage(e.toString()); + } + } + + Future _setAutoViewPadding(MapPadding padding) async { + try { + await _autoViewController.setPadding(padding); + setState(() { + _autoViewMapPadding = padding; + }); + } catch (e) { + showMessage(e.toString()); + } + } + @override Widget build(BuildContext context) => buildPage( context, @@ -1476,6 +1502,62 @@ class _NavigationPageState extends ExamplePageState { _trafficIndicentCardsEnabled = newValue; }); }), + Text('Map left padding: ${_mapPadding.left}'), + Slider( + value: _mapPadding.left.toDouble(), + min: 0, + max: 200, + divisions: 20, + label: _mapPadding.left.toString(), + onChanged: (double value) { + _setPadding(MapPadding( + top: _mapPadding.top, + left: value.round(), + bottom: _mapPadding.bottom, + right: _mapPadding.right)); + }), + Text('Map right padding: ${_mapPadding.right}'), + Slider( + value: _mapPadding.right.toDouble(), + min: 0, + max: 200, + divisions: 20, + label: _mapPadding.right.toString(), + onChanged: (double value) { + _setPadding(MapPadding( + top: _mapPadding.top, + left: _mapPadding.left, + bottom: _mapPadding.bottom, + right: value.round())); + }), + Text('Map top padding: ${_mapPadding.top}'), + Slider( + value: _mapPadding.top.toDouble(), + min: 0, + max: 200, + divisions: 20, + label: _mapPadding.top.toString(), + onChanged: (double value) { + _setPadding(MapPadding( + top: value.round(), + left: _mapPadding.left, + bottom: _mapPadding.bottom, + right: _mapPadding.right)); + }), + Text('Map bottom padding: ${_mapPadding.bottom}'), + Slider( + value: _mapPadding.bottom.toDouble(), + min: 0, + max: 200, + divisions: 20, + label: _mapPadding.bottom.toString(), + onChanged: (double value) { + _setPadding(MapPadding( + top: _mapPadding.top, + left: _mapPadding.left, + bottom: value.round(), + right: _mapPadding.right)); + }), ]), )), Card( @@ -1499,6 +1581,62 @@ class _NavigationPageState extends ExamplePageState { onPressed: () => _addMarkerForAuto(), child: const Text('Add marker'), ), + Text('Map left padding: ${_autoViewMapPadding.left}'), + Slider( + value: _autoViewMapPadding.left.toDouble(), + min: 0, + max: 200, + divisions: 20, + label: _autoViewMapPadding.left.toString(), + onChanged: (double value) { + _setAutoViewPadding(MapPadding( + top: _autoViewMapPadding.top, + left: value.round(), + bottom: _autoViewMapPadding.bottom, + right: _autoViewMapPadding.right)); + }), + Text('Map right padding: ${_autoViewMapPadding.right}'), + Slider( + value: _autoViewMapPadding.right.toDouble(), + min: 0, + max: 200, + divisions: 20, + label: _autoViewMapPadding.right.toString(), + onChanged: (double value) { + _setAutoViewPadding(MapPadding( + top: _autoViewMapPadding.top, + left: _autoViewMapPadding.left, + bottom: _autoViewMapPadding.bottom, + right: value.round())); + }), + Text('Map top padding: ${_autoViewMapPadding.top}'), + Slider( + value: _autoViewMapPadding.top.toDouble(), + min: 0, + max: 200, + divisions: 20, + label: _autoViewMapPadding.top.toString(), + onChanged: (double value) { + _setAutoViewPadding(MapPadding( + top: value.round(), + left: _autoViewMapPadding.left, + bottom: _autoViewMapPadding.bottom, + right: _autoViewMapPadding.right)); + }), + Text('Map bottom padding: ${_autoViewMapPadding.bottom}'), + Slider( + value: _autoViewMapPadding.bottom.toDouble(), + min: 0, + max: 200, + divisions: 20, + label: _autoViewMapPadding.bottom.toString(), + onChanged: (double value) { + _setAutoViewPadding(MapPadding( + top: _autoViewMapPadding.top, + left: _autoViewMapPadding.left, + bottom: value.round(), + right: _autoViewMapPadding.right)); + }), ]), ), IgnorePointer( diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsAutoViewMessageHandler.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsAutoViewMessageHandler.swift index 6048a58..9169d39 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsAutoViewMessageHandler.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsAutoViewMessageHandler.swift @@ -441,4 +441,8 @@ class GoogleMapsAutoViewMessageHandler: AutoMapViewApi { func isAutoScreenAvailable() throws -> Bool { viewRegistry.getCarPlayView() != nil } + + func setPadding(padding: MapPaddingDto) throws { + try getView().setPadding(padding: padding) + } } diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift index 6c0afa9..1707ef5 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift @@ -825,6 +825,15 @@ public class GoogleMapsNavigationView: NSObject, FlutterPlatformView, ViewSettle // boolean to control if camera changes are sent over the event channel. _listenCameraChanges = true } + + func setPadding(padding: MapPaddingDto) throws { + _mapView.padding = UIEdgeInsets( + top: CGFloat(padding.top), + left: CGFloat(padding.left), + bottom: CGFloat(padding.bottom), + right: CGFloat(padding.right) + ) + } } extension GoogleMapsNavigationView: GMSMapViewNavigationUIDelegate { diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewMessageHandler.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewMessageHandler.swift index 85b95e8..f4269a0 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewMessageHandler.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewMessageHandler.swift @@ -505,4 +505,8 @@ class GoogleMapsNavigationViewMessageHandler: MapViewApi { func registerOnCameraChangedListener(viewId: Int64) throws { try getView(viewId).registerOnCameraChangedListener() } + + func setPadding(viewId: Int64, padding: MapPaddingDto) throws { + try getView(viewId).setPadding(padding: padding) + } } diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift index b6071ea..c6e031a 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift @@ -1039,6 +1039,37 @@ struct CircleOptionsDto { } } +/// Generated class from Pigeon that represents data sent in messages. +struct MapPaddingDto { + var top: Int64 + var left: Int64 + var bottom: Int64 + var right: Int64 + + static func fromList(_ list: [Any?]) -> MapPaddingDto? { + let top = list[0] is Int64 ? list[0] as! Int64 : Int64(list[0] as! Int32) + let left = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + let bottom = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32) + let right = list[3] is Int64 ? list[3] as! Int64 : Int64(list[3] as! Int32) + + return MapPaddingDto( + top: top, + left: left, + bottom: bottom, + right: right + ) + } + + func toList() -> [Any?] { + [ + top, + left, + bottom, + right, + ] + } +} + /// Generated class from Pigeon that represents data sent in messages. struct RouteTokenOptionsDto { var routeToken: String @@ -1770,7 +1801,7 @@ protocol NavigationViewCreationApi { } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. -class NavigationViewCreationApiSetup { +enum NavigationViewCreationApiSetup { /// The codec used by NavigationViewCreationApi. static var codec: FlutterStandardMessageCodec { NavigationViewCreationApiCodec.shared } /// Sets up an instance of `NavigationViewCreationApi` to handle messages through the @@ -1818,26 +1849,28 @@ private class MapViewApiCodecReader: FlutterStandardReader { case 135: return LatLngDto.fromList(readValue() as! [Any?]) case 136: - return MarkerAnchorDto.fromList(readValue() as! [Any?]) + return MapPaddingDto.fromList(readValue() as! [Any?]) case 137: - return MarkerDto.fromList(readValue() as! [Any?]) + return MarkerAnchorDto.fromList(readValue() as! [Any?]) case 138: - return MarkerOptionsDto.fromList(readValue() as! [Any?]) + return MarkerDto.fromList(readValue() as! [Any?]) case 139: - return PatternItemDto.fromList(readValue() as! [Any?]) + return MarkerOptionsDto.fromList(readValue() as! [Any?]) case 140: - return PolygonDto.fromList(readValue() as! [Any?]) + return PatternItemDto.fromList(readValue() as! [Any?]) case 141: - return PolygonHoleDto.fromList(readValue() as! [Any?]) + return PolygonDto.fromList(readValue() as! [Any?]) case 142: - return PolygonOptionsDto.fromList(readValue() as! [Any?]) + return PolygonHoleDto.fromList(readValue() as! [Any?]) case 143: - return PolylineDto.fromList(readValue() as! [Any?]) + return PolygonOptionsDto.fromList(readValue() as! [Any?]) case 144: - return PolylineOptionsDto.fromList(readValue() as! [Any?]) + return PolylineDto.fromList(readValue() as! [Any?]) case 145: - return StyleSpanDto.fromList(readValue() as! [Any?]) + return PolylineOptionsDto.fromList(readValue() as! [Any?]) case 146: + return StyleSpanDto.fromList(readValue() as! [Any?]) + case 147: return StyleSpanStrokeStyleDto.fromList(readValue() as! [Any?]) default: return super.readValue(ofType: type) @@ -1871,39 +1904,42 @@ private class MapViewApiCodecWriter: FlutterStandardWriter { } else if let value = value as? LatLngDto { super.writeByte(135) super.writeValue(value.toList()) - } else if let value = value as? MarkerAnchorDto { + } else if let value = value as? MapPaddingDto { super.writeByte(136) super.writeValue(value.toList()) - } else if let value = value as? MarkerDto { + } else if let value = value as? MarkerAnchorDto { super.writeByte(137) super.writeValue(value.toList()) - } else if let value = value as? MarkerOptionsDto { + } else if let value = value as? MarkerDto { super.writeByte(138) super.writeValue(value.toList()) - } else if let value = value as? PatternItemDto { + } else if let value = value as? MarkerOptionsDto { super.writeByte(139) super.writeValue(value.toList()) - } else if let value = value as? PolygonDto { + } else if let value = value as? PatternItemDto { super.writeByte(140) super.writeValue(value.toList()) - } else if let value = value as? PolygonHoleDto { + } else if let value = value as? PolygonDto { super.writeByte(141) super.writeValue(value.toList()) - } else if let value = value as? PolygonOptionsDto { + } else if let value = value as? PolygonHoleDto { super.writeByte(142) super.writeValue(value.toList()) - } else if let value = value as? PolylineDto { + } else if let value = value as? PolygonOptionsDto { super.writeByte(143) super.writeValue(value.toList()) - } else if let value = value as? PolylineOptionsDto { + } else if let value = value as? PolylineDto { super.writeByte(144) super.writeValue(value.toList()) - } else if let value = value as? StyleSpanDto { + } else if let value = value as? PolylineOptionsDto { super.writeByte(145) super.writeValue(value.toList()) - } else if let value = value as? StyleSpanStrokeStyleDto { + } else if let value = value as? StyleSpanDto { super.writeByte(146) super.writeValue(value.toList()) + } else if let value = value as? StyleSpanStrokeStyleDto { + super.writeByte(147) + super.writeValue(value.toList()) } else { super.writeValue(value) } @@ -2025,10 +2061,11 @@ protocol MapViewApi { func removeCircles(viewId: Int64, circles: [CircleDto]) throws func clearCircles(viewId: Int64) throws func registerOnCameraChangedListener(viewId: Int64) throws + func setPadding(viewId: Int64, padding: MapPaddingDto) throws } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. -class MapViewApiSetup { +enum MapViewApiSetup { /// The codec used by MapViewApi. static var codec: FlutterStandardMessageCodec { MapViewApiCodec.shared } /// Sets up an instance of `MapViewApi` to handle messages through the `binaryMessenger`. @@ -3882,6 +3919,26 @@ class MapViewApiSetup { } else { registerOnCameraChangedListenerChannel.setMessageHandler(nil) } + let setPaddingChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.google_navigation_flutter.MapViewApi.setPadding", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + setPaddingChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let viewIdArg = args[0] is Int64 ? args[0] as! Int64 : Int64(args[0] as! Int32) + let paddingArg = args[1] as! MapPaddingDto + do { + try api.setPadding(viewId: viewIdArg, padding: paddingArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setPaddingChannel.setMessageHandler(nil) + } } } @@ -3937,7 +3994,7 @@ protocol ImageRegistryApi { } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. -class ImageRegistryApiSetup { +enum ImageRegistryApiSetup { /// The codec used by ImageRegistryApi. static var codec: FlutterStandardMessageCodec { ImageRegistryApiCodec.shared } /// Sets up an instance of `ImageRegistryApi` to handle messages through the `binaryMessenger`. @@ -4588,7 +4645,7 @@ protocol NavigationSessionApi { } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. -class NavigationSessionApiSetup { +enum NavigationSessionApiSetup { /// The codec used by NavigationSessionApi. static var codec: FlutterStandardMessageCodec { NavigationSessionApiCodec.shared } /// Sets up an instance of `NavigationSessionApi` to handle messages through the @@ -5629,26 +5686,28 @@ private class AutoMapViewApiCodecReader: FlutterStandardReader { case 135: return LatLngDto.fromList(readValue() as! [Any?]) case 136: - return MarkerAnchorDto.fromList(readValue() as! [Any?]) + return MapPaddingDto.fromList(readValue() as! [Any?]) case 137: - return MarkerDto.fromList(readValue() as! [Any?]) + return MarkerAnchorDto.fromList(readValue() as! [Any?]) case 138: - return MarkerOptionsDto.fromList(readValue() as! [Any?]) + return MarkerDto.fromList(readValue() as! [Any?]) case 139: - return PatternItemDto.fromList(readValue() as! [Any?]) + return MarkerOptionsDto.fromList(readValue() as! [Any?]) case 140: - return PolygonDto.fromList(readValue() as! [Any?]) + return PatternItemDto.fromList(readValue() as! [Any?]) case 141: - return PolygonHoleDto.fromList(readValue() as! [Any?]) + return PolygonDto.fromList(readValue() as! [Any?]) case 142: - return PolygonOptionsDto.fromList(readValue() as! [Any?]) + return PolygonHoleDto.fromList(readValue() as! [Any?]) case 143: - return PolylineDto.fromList(readValue() as! [Any?]) + return PolygonOptionsDto.fromList(readValue() as! [Any?]) case 144: - return PolylineOptionsDto.fromList(readValue() as! [Any?]) + return PolylineDto.fromList(readValue() as! [Any?]) case 145: - return StyleSpanDto.fromList(readValue() as! [Any?]) + return PolylineOptionsDto.fromList(readValue() as! [Any?]) case 146: + return StyleSpanDto.fromList(readValue() as! [Any?]) + case 147: return StyleSpanStrokeStyleDto.fromList(readValue() as! [Any?]) default: return super.readValue(ofType: type) @@ -5682,39 +5741,42 @@ private class AutoMapViewApiCodecWriter: FlutterStandardWriter { } else if let value = value as? LatLngDto { super.writeByte(135) super.writeValue(value.toList()) - } else if let value = value as? MarkerAnchorDto { + } else if let value = value as? MapPaddingDto { super.writeByte(136) super.writeValue(value.toList()) - } else if let value = value as? MarkerDto { + } else if let value = value as? MarkerAnchorDto { super.writeByte(137) super.writeValue(value.toList()) - } else if let value = value as? MarkerOptionsDto { + } else if let value = value as? MarkerDto { super.writeByte(138) super.writeValue(value.toList()) - } else if let value = value as? PatternItemDto { + } else if let value = value as? MarkerOptionsDto { super.writeByte(139) super.writeValue(value.toList()) - } else if let value = value as? PolygonDto { + } else if let value = value as? PatternItemDto { super.writeByte(140) super.writeValue(value.toList()) - } else if let value = value as? PolygonHoleDto { + } else if let value = value as? PolygonDto { super.writeByte(141) super.writeValue(value.toList()) - } else if let value = value as? PolygonOptionsDto { + } else if let value = value as? PolygonHoleDto { super.writeByte(142) super.writeValue(value.toList()) - } else if let value = value as? PolylineDto { + } else if let value = value as? PolygonOptionsDto { super.writeByte(143) super.writeValue(value.toList()) - } else if let value = value as? PolylineOptionsDto { + } else if let value = value as? PolylineDto { super.writeByte(144) super.writeValue(value.toList()) - } else if let value = value as? StyleSpanDto { + } else if let value = value as? PolylineOptionsDto { super.writeByte(145) super.writeValue(value.toList()) - } else if let value = value as? StyleSpanStrokeStyleDto { + } else if let value = value as? StyleSpanDto { super.writeByte(146) super.writeValue(value.toList()) + } else if let value = value as? StyleSpanStrokeStyleDto { + super.writeByte(147) + super.writeValue(value.toList()) } else { super.writeValue(value) } @@ -5817,10 +5879,11 @@ protocol AutoMapViewApi { func clearCircles() throws func registerOnCameraChangedListener() throws func isAutoScreenAvailable() throws -> Bool + func setPadding(padding: MapPaddingDto) throws } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. -class AutoMapViewApiSetup { +enum AutoMapViewApiSetup { /// The codec used by AutoMapViewApi. static var codec: FlutterStandardMessageCodec { AutoMapViewApiCodec.shared } /// Sets up an instance of `AutoMapViewApi` to handle messages through the `binaryMessenger`. @@ -7208,6 +7271,25 @@ class AutoMapViewApiSetup { } else { isAutoScreenAvailableChannel.setMessageHandler(nil) } + let setPaddingChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.google_navigation_flutter.AutoMapViewApi.setPadding", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + setPaddingChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let paddingArg = args[0] as! MapPaddingDto + do { + try api.setPadding(padding: paddingArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setPaddingChannel.setMessageHandler(nil) + } } } @@ -7237,58 +7319,60 @@ private class AutoViewEventApiCodecReader: FlutterStandardReader { case 138: return MapOptionsDto.fromList(readValue() as! [Any?]) case 139: - return MarkerAnchorDto.fromList(readValue() as! [Any?]) + return MapPaddingDto.fromList(readValue() as! [Any?]) case 140: - return MarkerDto.fromList(readValue() as! [Any?]) + return MarkerAnchorDto.fromList(readValue() as! [Any?]) case 141: - return MarkerOptionsDto.fromList(readValue() as! [Any?]) + return MarkerDto.fromList(readValue() as! [Any?]) case 142: - return NavInfoDto.fromList(readValue() as! [Any?]) + return MarkerOptionsDto.fromList(readValue() as! [Any?]) case 143: - return NavigationAudioGuidanceSettingsDto.fromList(readValue() as! [Any?]) + return NavInfoDto.fromList(readValue() as! [Any?]) case 144: - return NavigationDisplayOptionsDto.fromList(readValue() as! [Any?]) + return NavigationAudioGuidanceSettingsDto.fromList(readValue() as! [Any?]) case 145: - return NavigationTimeAndDistanceDto.fromList(readValue() as! [Any?]) + return NavigationDisplayOptionsDto.fromList(readValue() as! [Any?]) case 146: - return NavigationViewOptionsDto.fromList(readValue() as! [Any?]) + return NavigationTimeAndDistanceDto.fromList(readValue() as! [Any?]) case 147: - return NavigationWaypointDto.fromList(readValue() as! [Any?]) + return NavigationViewOptionsDto.fromList(readValue() as! [Any?]) case 148: - return PatternItemDto.fromList(readValue() as! [Any?]) + return NavigationWaypointDto.fromList(readValue() as! [Any?]) case 149: - return PolygonDto.fromList(readValue() as! [Any?]) + return PatternItemDto.fromList(readValue() as! [Any?]) case 150: - return PolygonHoleDto.fromList(readValue() as! [Any?]) + return PolygonDto.fromList(readValue() as! [Any?]) case 151: - return PolygonOptionsDto.fromList(readValue() as! [Any?]) + return PolygonHoleDto.fromList(readValue() as! [Any?]) case 152: - return PolylineDto.fromList(readValue() as! [Any?]) + return PolygonOptionsDto.fromList(readValue() as! [Any?]) case 153: - return PolylineOptionsDto.fromList(readValue() as! [Any?]) + return PolylineDto.fromList(readValue() as! [Any?]) case 154: - return RouteSegmentDto.fromList(readValue() as! [Any?]) + return PolylineOptionsDto.fromList(readValue() as! [Any?]) case 155: - return RouteSegmentTrafficDataDto.fromList(readValue() as! [Any?]) + return RouteSegmentDto.fromList(readValue() as! [Any?]) case 156: - return RouteSegmentTrafficDataRoadStretchRenderingDataDto.fromList(readValue() as! [Any?]) + return RouteSegmentTrafficDataDto.fromList(readValue() as! [Any?]) case 157: - return RouteTokenOptionsDto.fromList(readValue() as! [Any?]) + return RouteSegmentTrafficDataRoadStretchRenderingDataDto.fromList(readValue() as! [Any?]) case 158: - return RoutingOptionsDto.fromList(readValue() as! [Any?]) + return RouteTokenOptionsDto.fromList(readValue() as! [Any?]) case 159: - return SimulationOptionsDto.fromList(readValue() as! [Any?]) + return RoutingOptionsDto.fromList(readValue() as! [Any?]) case 160: - return SpeedAlertOptionsDto.fromList(readValue() as! [Any?]) + return SimulationOptionsDto.fromList(readValue() as! [Any?]) case 161: - return SpeedingUpdatedEventDto.fromList(readValue() as! [Any?]) + return SpeedAlertOptionsDto.fromList(readValue() as! [Any?]) case 162: - return StepInfoDto.fromList(readValue() as! [Any?]) + return SpeedingUpdatedEventDto.fromList(readValue() as! [Any?]) case 163: - return StyleSpanDto.fromList(readValue() as! [Any?]) + return StepInfoDto.fromList(readValue() as! [Any?]) case 164: - return StyleSpanStrokeStyleDto.fromList(readValue() as! [Any?]) + return StyleSpanDto.fromList(readValue() as! [Any?]) case 165: + return StyleSpanStrokeStyleDto.fromList(readValue() as! [Any?]) + case 166: return ViewCreationOptionsDto.fromList(readValue() as! [Any?]) default: return super.readValue(ofType: type) @@ -7331,87 +7415,90 @@ private class AutoViewEventApiCodecWriter: FlutterStandardWriter { } else if let value = value as? MapOptionsDto { super.writeByte(138) super.writeValue(value.toList()) - } else if let value = value as? MarkerAnchorDto { + } else if let value = value as? MapPaddingDto { super.writeByte(139) super.writeValue(value.toList()) - } else if let value = value as? MarkerDto { + } else if let value = value as? MarkerAnchorDto { super.writeByte(140) super.writeValue(value.toList()) - } else if let value = value as? MarkerOptionsDto { + } else if let value = value as? MarkerDto { super.writeByte(141) super.writeValue(value.toList()) - } else if let value = value as? NavInfoDto { + } else if let value = value as? MarkerOptionsDto { super.writeByte(142) super.writeValue(value.toList()) - } else if let value = value as? NavigationAudioGuidanceSettingsDto { + } else if let value = value as? NavInfoDto { super.writeByte(143) super.writeValue(value.toList()) - } else if let value = value as? NavigationDisplayOptionsDto { + } else if let value = value as? NavigationAudioGuidanceSettingsDto { super.writeByte(144) super.writeValue(value.toList()) - } else if let value = value as? NavigationTimeAndDistanceDto { + } else if let value = value as? NavigationDisplayOptionsDto { super.writeByte(145) super.writeValue(value.toList()) - } else if let value = value as? NavigationViewOptionsDto { + } else if let value = value as? NavigationTimeAndDistanceDto { super.writeByte(146) super.writeValue(value.toList()) - } else if let value = value as? NavigationWaypointDto { + } else if let value = value as? NavigationViewOptionsDto { super.writeByte(147) super.writeValue(value.toList()) - } else if let value = value as? PatternItemDto { + } else if let value = value as? NavigationWaypointDto { super.writeByte(148) super.writeValue(value.toList()) - } else if let value = value as? PolygonDto { + } else if let value = value as? PatternItemDto { super.writeByte(149) super.writeValue(value.toList()) - } else if let value = value as? PolygonHoleDto { + } else if let value = value as? PolygonDto { super.writeByte(150) super.writeValue(value.toList()) - } else if let value = value as? PolygonOptionsDto { + } else if let value = value as? PolygonHoleDto { super.writeByte(151) super.writeValue(value.toList()) - } else if let value = value as? PolylineDto { + } else if let value = value as? PolygonOptionsDto { super.writeByte(152) super.writeValue(value.toList()) - } else if let value = value as? PolylineOptionsDto { + } else if let value = value as? PolylineDto { super.writeByte(153) super.writeValue(value.toList()) - } else if let value = value as? RouteSegmentDto { + } else if let value = value as? PolylineOptionsDto { super.writeByte(154) super.writeValue(value.toList()) - } else if let value = value as? RouteSegmentTrafficDataDto { + } else if let value = value as? RouteSegmentDto { super.writeByte(155) super.writeValue(value.toList()) - } else if let value = value as? RouteSegmentTrafficDataRoadStretchRenderingDataDto { + } else if let value = value as? RouteSegmentTrafficDataDto { super.writeByte(156) super.writeValue(value.toList()) - } else if let value = value as? RouteTokenOptionsDto { + } else if let value = value as? RouteSegmentTrafficDataRoadStretchRenderingDataDto { super.writeByte(157) super.writeValue(value.toList()) - } else if let value = value as? RoutingOptionsDto { + } else if let value = value as? RouteTokenOptionsDto { super.writeByte(158) super.writeValue(value.toList()) - } else if let value = value as? SimulationOptionsDto { + } else if let value = value as? RoutingOptionsDto { super.writeByte(159) super.writeValue(value.toList()) - } else if let value = value as? SpeedAlertOptionsDto { + } else if let value = value as? SimulationOptionsDto { super.writeByte(160) super.writeValue(value.toList()) - } else if let value = value as? SpeedingUpdatedEventDto { + } else if let value = value as? SpeedAlertOptionsDto { super.writeByte(161) super.writeValue(value.toList()) - } else if let value = value as? StepInfoDto { + } else if let value = value as? SpeedingUpdatedEventDto { super.writeByte(162) super.writeValue(value.toList()) - } else if let value = value as? StyleSpanDto { + } else if let value = value as? StepInfoDto { super.writeByte(163) super.writeValue(value.toList()) - } else if let value = value as? StyleSpanStrokeStyleDto { + } else if let value = value as? StyleSpanDto { super.writeByte(164) super.writeValue(value.toList()) - } else if let value = value as? ViewCreationOptionsDto { + } else if let value = value as? StyleSpanStrokeStyleDto { super.writeByte(165) super.writeValue(value.toList()) + } else if let value = value as? ViewCreationOptionsDto { + super.writeByte(166) + super.writeValue(value.toList()) } else { super.writeValue(value) } @@ -7507,7 +7594,7 @@ protocol NavigationInspector { } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. -class NavigationInspectorSetup { +enum NavigationInspectorSetup { /// The codec used by NavigationInspector. /// Sets up an instance of `NavigationInspector` to handle messages through the `binaryMessenger`. static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NavigationInspector?) { diff --git a/lib/src/google_maps_auto_view_controller.dart b/lib/src/google_maps_auto_view_controller.dart index ae332e7..cc5360c 100644 --- a/lib/src/google_maps_auto_view_controller.dart +++ b/lib/src/google_maps_auto_view_controller.dart @@ -325,6 +325,11 @@ class GoogleMapsAutoViewController { return GoogleMapsNavigationPlatform.instance.clearForAuto(); } + Future setPadding(MapPadding padding) { + return GoogleMapsNavigationPlatform.instance + .setPaddingForAuto(padding: padding); + } + Future isAutoScreenAvailable() { return GoogleMapsNavigationPlatform.instance.isAutoScreenAvailable(); } diff --git a/lib/src/google_maps_map_view_controller.dart b/lib/src/google_maps_map_view_controller.dart index fa1604b..6d640fb 100644 --- a/lib/src/google_maps_map_view_controller.dart +++ b/lib/src/google_maps_map_view_controller.dart @@ -363,4 +363,10 @@ class GoogleMapViewController { Future clear() { return GoogleMapsNavigationPlatform.instance.clear(viewId: _viewId); } + + /// Set padding for the map view. + Future setPadding(MapPadding 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 288f3f6..74a1298 100644 --- a/lib/src/google_navigation_flutter_platform_interface.dart +++ b/lib/src/google_navigation_flutter_platform_interface.dart @@ -532,6 +532,9 @@ abstract mixin class MapViewAPIInterface { /// Register camera changed listeners. Future registerOnCameraChangedListener({required int viewId}); + // Sets the map padding for the map view. + Future setPadding({required int viewId, required MapPadding padding}); + /// Get navigation view marker event stream from the navigation view. Stream getMarkerEventStream({required int viewId}); @@ -769,6 +772,9 @@ abstract mixin class AutoMapViewAPIInterface { // Check whether auto screen is available; Future isAutoScreenAvailable(); + // Sets the map padding for the auto map view. + Future setPaddingForAuto({required MapPadding 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 88d70b1..bd31bca 100644 --- a/lib/src/method_channel/common_auto_view_api.dart +++ b/lib/src/method_channel/common_auto_view_api.dart @@ -735,6 +735,15 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { return _viewApi.registerOnCameraChangedListener(); } + @override + Future setPaddingForAuto({required MapPadding padding}) { + return _viewApi.setPadding(MapPaddingDto( + top: padding.top, + left: padding.left, + bottom: padding.bottom, + right: padding.right)); + } + @override Future isAutoScreenAvailable() { return _viewApi.isAutoScreenAvailable(); diff --git a/lib/src/method_channel/common_view_api.dart b/lib/src/method_channel/common_view_api.dart index 342dc46..5e79b48 100644 --- a/lib/src/method_channel/common_view_api.dart +++ b/lib/src/method_channel/common_view_api.dart @@ -935,6 +935,17 @@ mixin CommonMapViewAPI on MapViewAPIInterface { return _viewApi.registerOnCameraChangedListener(viewId); } + @override + Future setPadding({required int viewId, required MapPadding padding}) { + return _viewApi.setPadding( + viewId, + MapPaddingDto( + top: padding.top, + left: padding.left, + bottom: padding.bottom, + right: padding.right)); + } + @override Stream getMapClickEventStream({required int viewId}) { return _unwrapEventStream(viewId: viewId); diff --git a/lib/src/method_channel/messages.g.dart b/lib/src/method_channel/messages.g.dart index 6c19dba..9576b7e 100644 --- a/lib/src/method_channel/messages.g.dart +++ b/lib/src/method_channel/messages.g.dart @@ -1191,6 +1191,42 @@ class CircleOptionsDto { } } +class MapPaddingDto { + MapPaddingDto({ + required this.top, + required this.left, + required this.bottom, + required this.right, + }); + + int top; + + int left; + + int bottom; + + int right; + + Object encode() { + return [ + top, + left, + bottom, + right, + ]; + } + + static MapPaddingDto decode(Object result) { + result as List; + return MapPaddingDto( + top: result[0]! as int, + left: result[1]! as int, + bottom: result[2]! as int, + right: result[3]! as int, + ); + } +} + class RouteTokenOptionsDto { RouteTokenOptionsDto({ required this.routeToken, @@ -2025,39 +2061,42 @@ class _MapViewApiCodec extends StandardMessageCodec { } else if (value is LatLngDto) { buffer.putUint8(135); writeValue(buffer, value.encode()); - } else if (value is MarkerAnchorDto) { + } else if (value is MapPaddingDto) { buffer.putUint8(136); writeValue(buffer, value.encode()); - } else if (value is MarkerDto) { + } else if (value is MarkerAnchorDto) { buffer.putUint8(137); writeValue(buffer, value.encode()); - } else if (value is MarkerOptionsDto) { + } else if (value is MarkerDto) { buffer.putUint8(138); writeValue(buffer, value.encode()); - } else if (value is PatternItemDto) { + } else if (value is MarkerOptionsDto) { buffer.putUint8(139); writeValue(buffer, value.encode()); - } else if (value is PolygonDto) { + } else if (value is PatternItemDto) { buffer.putUint8(140); writeValue(buffer, value.encode()); - } else if (value is PolygonHoleDto) { + } else if (value is PolygonDto) { buffer.putUint8(141); writeValue(buffer, value.encode()); - } else if (value is PolygonOptionsDto) { + } else if (value is PolygonHoleDto) { buffer.putUint8(142); writeValue(buffer, value.encode()); - } else if (value is PolylineDto) { + } else if (value is PolygonOptionsDto) { buffer.putUint8(143); writeValue(buffer, value.encode()); - } else if (value is PolylineOptionsDto) { + } else if (value is PolylineDto) { buffer.putUint8(144); writeValue(buffer, value.encode()); - } else if (value is StyleSpanDto) { + } else if (value is PolylineOptionsDto) { buffer.putUint8(145); writeValue(buffer, value.encode()); - } else if (value is StyleSpanStrokeStyleDto) { + } else if (value is StyleSpanDto) { buffer.putUint8(146); writeValue(buffer, value.encode()); + } else if (value is StyleSpanStrokeStyleDto) { + buffer.putUint8(147); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -2083,26 +2122,28 @@ class _MapViewApiCodec extends StandardMessageCodec { case 135: return LatLngDto.decode(readValue(buffer)!); case 136: - return MarkerAnchorDto.decode(readValue(buffer)!); + return MapPaddingDto.decode(readValue(buffer)!); case 137: - return MarkerDto.decode(readValue(buffer)!); + return MarkerAnchorDto.decode(readValue(buffer)!); case 138: - return MarkerOptionsDto.decode(readValue(buffer)!); + return MarkerDto.decode(readValue(buffer)!); case 139: - return PatternItemDto.decode(readValue(buffer)!); + return MarkerOptionsDto.decode(readValue(buffer)!); case 140: - return PolygonDto.decode(readValue(buffer)!); + return PatternItemDto.decode(readValue(buffer)!); case 141: - return PolygonHoleDto.decode(readValue(buffer)!); + return PolygonDto.decode(readValue(buffer)!); case 142: - return PolygonOptionsDto.decode(readValue(buffer)!); + return PolygonHoleDto.decode(readValue(buffer)!); case 143: - return PolylineDto.decode(readValue(buffer)!); + return PolygonOptionsDto.decode(readValue(buffer)!); case 144: - return PolylineOptionsDto.decode(readValue(buffer)!); + return PolylineDto.decode(readValue(buffer)!); case 145: - return StyleSpanDto.decode(readValue(buffer)!); + return PolylineOptionsDto.decode(readValue(buffer)!); case 146: + return StyleSpanDto.decode(readValue(buffer)!); + case 147: return StyleSpanStrokeStyleDto.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -4528,6 +4569,30 @@ class MapViewApi { return; } } + + Future setPadding(int viewId, MapPaddingDto padding) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.google_navigation_flutter.MapViewApi.setPadding'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([viewId, padding]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } } class _ImageRegistryApiCodec extends StandardMessageCodec { @@ -6532,39 +6597,42 @@ class _AutoMapViewApiCodec extends StandardMessageCodec { } else if (value is LatLngDto) { buffer.putUint8(135); writeValue(buffer, value.encode()); - } else if (value is MarkerAnchorDto) { + } else if (value is MapPaddingDto) { buffer.putUint8(136); writeValue(buffer, value.encode()); - } else if (value is MarkerDto) { + } else if (value is MarkerAnchorDto) { buffer.putUint8(137); writeValue(buffer, value.encode()); - } else if (value is MarkerOptionsDto) { + } else if (value is MarkerDto) { buffer.putUint8(138); writeValue(buffer, value.encode()); - } else if (value is PatternItemDto) { + } else if (value is MarkerOptionsDto) { buffer.putUint8(139); writeValue(buffer, value.encode()); - } else if (value is PolygonDto) { + } else if (value is PatternItemDto) { buffer.putUint8(140); writeValue(buffer, value.encode()); - } else if (value is PolygonHoleDto) { + } else if (value is PolygonDto) { buffer.putUint8(141); writeValue(buffer, value.encode()); - } else if (value is PolygonOptionsDto) { + } else if (value is PolygonHoleDto) { buffer.putUint8(142); writeValue(buffer, value.encode()); - } else if (value is PolylineDto) { + } else if (value is PolygonOptionsDto) { buffer.putUint8(143); writeValue(buffer, value.encode()); - } else if (value is PolylineOptionsDto) { + } else if (value is PolylineDto) { buffer.putUint8(144); writeValue(buffer, value.encode()); - } else if (value is StyleSpanDto) { + } else if (value is PolylineOptionsDto) { buffer.putUint8(145); writeValue(buffer, value.encode()); - } else if (value is StyleSpanStrokeStyleDto) { + } else if (value is StyleSpanDto) { buffer.putUint8(146); writeValue(buffer, value.encode()); + } else if (value is StyleSpanStrokeStyleDto) { + buffer.putUint8(147); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -6590,26 +6658,28 @@ class _AutoMapViewApiCodec extends StandardMessageCodec { case 135: return LatLngDto.decode(readValue(buffer)!); case 136: - return MarkerAnchorDto.decode(readValue(buffer)!); + return MapPaddingDto.decode(readValue(buffer)!); case 137: - return MarkerDto.decode(readValue(buffer)!); + return MarkerAnchorDto.decode(readValue(buffer)!); case 138: - return MarkerOptionsDto.decode(readValue(buffer)!); + return MarkerDto.decode(readValue(buffer)!); case 139: - return PatternItemDto.decode(readValue(buffer)!); + return MarkerOptionsDto.decode(readValue(buffer)!); case 140: - return PolygonDto.decode(readValue(buffer)!); + return PatternItemDto.decode(readValue(buffer)!); case 141: - return PolygonHoleDto.decode(readValue(buffer)!); + return PolygonDto.decode(readValue(buffer)!); case 142: - return PolygonOptionsDto.decode(readValue(buffer)!); + return PolygonHoleDto.decode(readValue(buffer)!); case 143: - return PolylineDto.decode(readValue(buffer)!); + return PolygonOptionsDto.decode(readValue(buffer)!); case 144: - return PolylineOptionsDto.decode(readValue(buffer)!); + return PolylineDto.decode(readValue(buffer)!); case 145: - return StyleSpanDto.decode(readValue(buffer)!); + return PolylineOptionsDto.decode(readValue(buffer)!); case 146: + return StyleSpanDto.decode(readValue(buffer)!); + case 147: return StyleSpanStrokeStyleDto.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -8575,6 +8645,30 @@ class AutoMapViewApi { return (__pigeon_replyList[0] as bool?)!; } } + + Future setPadding(MapPaddingDto padding) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.google_navigation_flutter.AutoMapViewApi.setPadding'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([padding]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } } class _AutoViewEventApiCodec extends StandardMessageCodec { @@ -8614,87 +8708,90 @@ class _AutoViewEventApiCodec extends StandardMessageCodec { } else if (value is MapOptionsDto) { buffer.putUint8(138); writeValue(buffer, value.encode()); - } else if (value is MarkerAnchorDto) { + } else if (value is MapPaddingDto) { buffer.putUint8(139); writeValue(buffer, value.encode()); - } else if (value is MarkerDto) { + } else if (value is MarkerAnchorDto) { buffer.putUint8(140); writeValue(buffer, value.encode()); - } else if (value is MarkerOptionsDto) { + } else if (value is MarkerDto) { buffer.putUint8(141); writeValue(buffer, value.encode()); - } else if (value is NavInfoDto) { + } else if (value is MarkerOptionsDto) { buffer.putUint8(142); writeValue(buffer, value.encode()); - } else if (value is NavigationAudioGuidanceSettingsDto) { + } else if (value is NavInfoDto) { buffer.putUint8(143); writeValue(buffer, value.encode()); - } else if (value is NavigationDisplayOptionsDto) { + } else if (value is NavigationAudioGuidanceSettingsDto) { buffer.putUint8(144); writeValue(buffer, value.encode()); - } else if (value is NavigationTimeAndDistanceDto) { + } else if (value is NavigationDisplayOptionsDto) { buffer.putUint8(145); writeValue(buffer, value.encode()); - } else if (value is NavigationViewOptionsDto) { + } else if (value is NavigationTimeAndDistanceDto) { buffer.putUint8(146); writeValue(buffer, value.encode()); - } else if (value is NavigationWaypointDto) { + } else if (value is NavigationViewOptionsDto) { buffer.putUint8(147); writeValue(buffer, value.encode()); - } else if (value is PatternItemDto) { + } else if (value is NavigationWaypointDto) { buffer.putUint8(148); writeValue(buffer, value.encode()); - } else if (value is PolygonDto) { + } else if (value is PatternItemDto) { buffer.putUint8(149); writeValue(buffer, value.encode()); - } else if (value is PolygonHoleDto) { + } else if (value is PolygonDto) { buffer.putUint8(150); writeValue(buffer, value.encode()); - } else if (value is PolygonOptionsDto) { + } else if (value is PolygonHoleDto) { buffer.putUint8(151); writeValue(buffer, value.encode()); - } else if (value is PolylineDto) { + } else if (value is PolygonOptionsDto) { buffer.putUint8(152); writeValue(buffer, value.encode()); - } else if (value is PolylineOptionsDto) { + } else if (value is PolylineDto) { buffer.putUint8(153); writeValue(buffer, value.encode()); - } else if (value is RouteSegmentDto) { + } else if (value is PolylineOptionsDto) { buffer.putUint8(154); writeValue(buffer, value.encode()); - } else if (value is RouteSegmentTrafficDataDto) { + } else if (value is RouteSegmentDto) { buffer.putUint8(155); writeValue(buffer, value.encode()); - } else if (value is RouteSegmentTrafficDataRoadStretchRenderingDataDto) { + } else if (value is RouteSegmentTrafficDataDto) { buffer.putUint8(156); writeValue(buffer, value.encode()); - } else if (value is RouteTokenOptionsDto) { + } else if (value is RouteSegmentTrafficDataRoadStretchRenderingDataDto) { buffer.putUint8(157); writeValue(buffer, value.encode()); - } else if (value is RoutingOptionsDto) { + } else if (value is RouteTokenOptionsDto) { buffer.putUint8(158); writeValue(buffer, value.encode()); - } else if (value is SimulationOptionsDto) { + } else if (value is RoutingOptionsDto) { buffer.putUint8(159); writeValue(buffer, value.encode()); - } else if (value is SpeedAlertOptionsDto) { + } else if (value is SimulationOptionsDto) { buffer.putUint8(160); writeValue(buffer, value.encode()); - } else if (value is SpeedingUpdatedEventDto) { + } else if (value is SpeedAlertOptionsDto) { buffer.putUint8(161); writeValue(buffer, value.encode()); - } else if (value is StepInfoDto) { + } else if (value is SpeedingUpdatedEventDto) { buffer.putUint8(162); writeValue(buffer, value.encode()); - } else if (value is StyleSpanDto) { + } else if (value is StepInfoDto) { buffer.putUint8(163); writeValue(buffer, value.encode()); - } else if (value is StyleSpanStrokeStyleDto) { + } else if (value is StyleSpanDto) { buffer.putUint8(164); writeValue(buffer, value.encode()); - } else if (value is ViewCreationOptionsDto) { + } else if (value is StyleSpanStrokeStyleDto) { buffer.putUint8(165); writeValue(buffer, value.encode()); + } else if (value is ViewCreationOptionsDto) { + buffer.putUint8(166); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -8726,59 +8823,61 @@ class _AutoViewEventApiCodec extends StandardMessageCodec { case 138: return MapOptionsDto.decode(readValue(buffer)!); case 139: - return MarkerAnchorDto.decode(readValue(buffer)!); + return MapPaddingDto.decode(readValue(buffer)!); case 140: - return MarkerDto.decode(readValue(buffer)!); + return MarkerAnchorDto.decode(readValue(buffer)!); case 141: - return MarkerOptionsDto.decode(readValue(buffer)!); + return MarkerDto.decode(readValue(buffer)!); case 142: - return NavInfoDto.decode(readValue(buffer)!); + return MarkerOptionsDto.decode(readValue(buffer)!); case 143: - return NavigationAudioGuidanceSettingsDto.decode(readValue(buffer)!); + return NavInfoDto.decode(readValue(buffer)!); case 144: - return NavigationDisplayOptionsDto.decode(readValue(buffer)!); + return NavigationAudioGuidanceSettingsDto.decode(readValue(buffer)!); case 145: - return NavigationTimeAndDistanceDto.decode(readValue(buffer)!); + return NavigationDisplayOptionsDto.decode(readValue(buffer)!); case 146: - return NavigationViewOptionsDto.decode(readValue(buffer)!); + return NavigationTimeAndDistanceDto.decode(readValue(buffer)!); case 147: - return NavigationWaypointDto.decode(readValue(buffer)!); + return NavigationViewOptionsDto.decode(readValue(buffer)!); case 148: - return PatternItemDto.decode(readValue(buffer)!); + return NavigationWaypointDto.decode(readValue(buffer)!); case 149: - return PolygonDto.decode(readValue(buffer)!); + return PatternItemDto.decode(readValue(buffer)!); case 150: - return PolygonHoleDto.decode(readValue(buffer)!); + return PolygonDto.decode(readValue(buffer)!); case 151: - return PolygonOptionsDto.decode(readValue(buffer)!); + return PolygonHoleDto.decode(readValue(buffer)!); case 152: - return PolylineDto.decode(readValue(buffer)!); + return PolygonOptionsDto.decode(readValue(buffer)!); case 153: - return PolylineOptionsDto.decode(readValue(buffer)!); + return PolylineDto.decode(readValue(buffer)!); case 154: - return RouteSegmentDto.decode(readValue(buffer)!); + return PolylineOptionsDto.decode(readValue(buffer)!); case 155: - return RouteSegmentTrafficDataDto.decode(readValue(buffer)!); + return RouteSegmentDto.decode(readValue(buffer)!); case 156: + return RouteSegmentTrafficDataDto.decode(readValue(buffer)!); + case 157: return RouteSegmentTrafficDataRoadStretchRenderingDataDto.decode( readValue(buffer)!); - case 157: - return RouteTokenOptionsDto.decode(readValue(buffer)!); case 158: - return RoutingOptionsDto.decode(readValue(buffer)!); + return RouteTokenOptionsDto.decode(readValue(buffer)!); case 159: - return SimulationOptionsDto.decode(readValue(buffer)!); + return RoutingOptionsDto.decode(readValue(buffer)!); case 160: - return SpeedAlertOptionsDto.decode(readValue(buffer)!); + return SimulationOptionsDto.decode(readValue(buffer)!); case 161: - return SpeedingUpdatedEventDto.decode(readValue(buffer)!); + return SpeedAlertOptionsDto.decode(readValue(buffer)!); case 162: - return StepInfoDto.decode(readValue(buffer)!); + return SpeedingUpdatedEventDto.decode(readValue(buffer)!); case 163: - return StyleSpanDto.decode(readValue(buffer)!); + return StepInfoDto.decode(readValue(buffer)!); case 164: - return StyleSpanStrokeStyleDto.decode(readValue(buffer)!); + return StyleSpanDto.decode(readValue(buffer)!); case 165: + return StyleSpanStrokeStyleDto.decode(readValue(buffer)!); + case 166: return ViewCreationOptionsDto.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); diff --git a/lib/src/types/navigation_view_types.dart b/lib/src/types/navigation_view_types.dart index e54e098..c4d47e9 100644 --- a/lib/src/types/navigation_view_types.dart +++ b/lib/src/types/navigation_view_types.dart @@ -439,3 +439,19 @@ 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/pigeons/messages.dart b/pigeons/messages.dart index b351b76..244edd0 100644 --- a/pigeons/messages.dart +++ b/pigeons/messages.dart @@ -378,6 +378,19 @@ enum CameraEventTypeDto { onCameraStoppedFollowingLocation } +class MapPaddingDto { + MapPaddingDto( + {required this.top, + required this.left, + required this.bottom, + required this.right}); + + final int top; + final int left; + final int bottom; + final int right; +} + @HostApi(dartHostTestHandler: 'TestMapViewApi') abstract class MapViewApi { @async @@ -498,6 +511,7 @@ abstract class MapViewApi { void clearCircles(int viewId); void registerOnCameraChangedListener(int viewId); + void setPadding(int viewId, MapPaddingDto padding); } @HostApi(dartHostTestHandler: 'TestImageRegistryApi') @@ -1352,6 +1366,7 @@ abstract class AutoMapViewApi { void registerOnCameraChangedListener(); bool isAutoScreenAvailable(); + void setPadding(MapPaddingDto padding); } @FlutterApi() diff --git a/test/messages_test.g.dart b/test/messages_test.g.dart index e753f6c..4d085ac 100644 --- a/test/messages_test.g.dart +++ b/test/messages_test.g.dart @@ -52,39 +52,42 @@ class _TestMapViewApiCodec extends StandardMessageCodec { } else if (value is LatLngDto) { buffer.putUint8(135); writeValue(buffer, value.encode()); - } else if (value is MarkerAnchorDto) { + } else if (value is MapPaddingDto) { buffer.putUint8(136); writeValue(buffer, value.encode()); - } else if (value is MarkerDto) { + } else if (value is MarkerAnchorDto) { buffer.putUint8(137); writeValue(buffer, value.encode()); - } else if (value is MarkerOptionsDto) { + } else if (value is MarkerDto) { buffer.putUint8(138); writeValue(buffer, value.encode()); - } else if (value is PatternItemDto) { + } else if (value is MarkerOptionsDto) { buffer.putUint8(139); writeValue(buffer, value.encode()); - } else if (value is PolygonDto) { + } else if (value is PatternItemDto) { buffer.putUint8(140); writeValue(buffer, value.encode()); - } else if (value is PolygonHoleDto) { + } else if (value is PolygonDto) { buffer.putUint8(141); writeValue(buffer, value.encode()); - } else if (value is PolygonOptionsDto) { + } else if (value is PolygonHoleDto) { buffer.putUint8(142); writeValue(buffer, value.encode()); - } else if (value is PolylineDto) { + } else if (value is PolygonOptionsDto) { buffer.putUint8(143); writeValue(buffer, value.encode()); - } else if (value is PolylineOptionsDto) { + } else if (value is PolylineDto) { buffer.putUint8(144); writeValue(buffer, value.encode()); - } else if (value is StyleSpanDto) { + } else if (value is PolylineOptionsDto) { buffer.putUint8(145); writeValue(buffer, value.encode()); - } else if (value is StyleSpanStrokeStyleDto) { + } else if (value is StyleSpanDto) { buffer.putUint8(146); writeValue(buffer, value.encode()); + } else if (value is StyleSpanStrokeStyleDto) { + buffer.putUint8(147); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -110,26 +113,28 @@ class _TestMapViewApiCodec extends StandardMessageCodec { case 135: return LatLngDto.decode(readValue(buffer)!); case 136: - return MarkerAnchorDto.decode(readValue(buffer)!); + return MapPaddingDto.decode(readValue(buffer)!); case 137: - return MarkerDto.decode(readValue(buffer)!); + return MarkerAnchorDto.decode(readValue(buffer)!); case 138: - return MarkerOptionsDto.decode(readValue(buffer)!); + return MarkerDto.decode(readValue(buffer)!); case 139: - return PatternItemDto.decode(readValue(buffer)!); + return MarkerOptionsDto.decode(readValue(buffer)!); case 140: - return PolygonDto.decode(readValue(buffer)!); + return PatternItemDto.decode(readValue(buffer)!); case 141: - return PolygonHoleDto.decode(readValue(buffer)!); + return PolygonDto.decode(readValue(buffer)!); case 142: - return PolygonOptionsDto.decode(readValue(buffer)!); + return PolygonHoleDto.decode(readValue(buffer)!); case 143: - return PolylineDto.decode(readValue(buffer)!); + return PolygonOptionsDto.decode(readValue(buffer)!); case 144: - return PolylineOptionsDto.decode(readValue(buffer)!); + return PolylineDto.decode(readValue(buffer)!); case 145: - return StyleSpanDto.decode(readValue(buffer)!); + return PolylineOptionsDto.decode(readValue(buffer)!); case 146: + return StyleSpanDto.decode(readValue(buffer)!); + case 147: return StyleSpanStrokeStyleDto.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -332,6 +337,8 @@ abstract class TestMapViewApi { void registerOnCameraChangedListener(int viewId); + void setPadding(int viewId, MapPaddingDto padding); + static void setup(TestMapViewApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel __pigeon_channel = BasicMessageChannel< @@ -3346,6 +3353,40 @@ abstract class TestMapViewApi { }); } } + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.google_navigation_flutter.MapViewApi.setPadding', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, + (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.google_navigation_flutter.MapViewApi.setPadding was null.'); + final List args = (message as List?)!; + final int? arg_viewId = (args[0] as int?); + assert(arg_viewId != null, + 'Argument for dev.flutter.pigeon.google_navigation_flutter.MapViewApi.setPadding was null, expected non-null int.'); + final MapPaddingDto? arg_padding = (args[1] as MapPaddingDto?); + assert(arg_padding != null, + 'Argument for dev.flutter.pigeon.google_navigation_flutter.MapViewApi.setPadding was null, expected non-null MapPaddingDto.'); + try { + api.setPadding(arg_viewId!, arg_padding!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } } From 55c2cc1a7ecbc067a7ee1eef35bd5228ae9a4d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4limaa?= Date: Mon, 9 Dec 2024 16:52:11 +0800 Subject: [PATCH 2/7] feat: add padding to map init params --- .../navigation/AndroidAutoBaseScreen.kt | 2 +- .../google/maps/flutter/navigation/Convert.kt | 32 +++++----- .../maps/flutter/navigation/GoogleMapView.kt | 6 +- .../navigation/GoogleMapsAutoMapView.kt | 3 +- .../navigation/GoogleMapsBaseMapView.kt | 7 +-- .../navigation/GoogleMapsNavigationView.kt | 8 +-- .../maps/flutter/navigation/MapOptions.kt | 21 +++++++ .../maps/flutter/navigation/messages.g.kt | 18 +++++- .../maps/flutter/navigation/ConvertTest.kt | 62 ++++++++++++------- example/lib/pages/navigation.dart | 3 +- example/lib/pages/widget_initialization.dart | 5 ++ .../Convert+MapConfiguration.swift | 8 ++- .../MapConfiguration.swift | 2 + .../messages.g.swift | 21 +++++-- lib/src/google_maps_map_view.dart | 8 +++ lib/src/google_maps_navigation_view.dart | 2 + lib/src/method_channel/common_view_api.dart | 3 +- lib/src/method_channel/convert/convert.dart | 1 + .../method_channel/convert/map_padding.dart | 25 ++++++++ lib/src/method_channel/messages.g.dart | 19 +++++- .../types/view_initialization_options.dart | 6 ++ pigeons/messages.dart | 4 ++ 22 files changed, 201 insertions(+), 65 deletions(-) create mode 100644 android/src/main/kotlin/com/google/maps/flutter/navigation/MapOptions.kt create mode 100644 lib/src/method_channel/convert/map_padding.dart diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/AndroidAutoBaseScreen.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/AndroidAutoBaseScreen.kt index c2fff07..574e656 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/AndroidAutoBaseScreen.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/AndroidAutoBaseScreen.kt @@ -121,7 +121,7 @@ open class AndroidAutoBaseScreen(carContext: CarContext) : mViewRegistry = viewRegistry mAutoMapView = GoogleMapsAutoMapView( - GoogleMapOptions(), + MapOptions(GoogleMapOptions(), null), viewRegistry, imageRegistry, navigationView, diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/Convert.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/Convert.kt index f69e1a3..ae580f0 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/Convert.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/Convert.kt @@ -61,28 +61,28 @@ object Convert { * @param options pigeon message [NavigationViewCreationOptionsDto]. * @return Google Map Options [GoogleMapOptions]. */ - fun convertMapOptionsFromDto(options: MapOptionsDto): GoogleMapOptions { - val mapOptions = GoogleMapOptions() + fun convertMapOptionsFromDto(options: MapOptionsDto): MapOptions { + val googleMapOptions = GoogleMapOptions() - mapOptions.camera(convertCameraPositionFromDto(options.cameraPosition)) - mapOptions.mapType(convertMapTypeFromDto(options.mapType)) - mapOptions.compassEnabled(options.compassEnabled) - mapOptions.rotateGesturesEnabled(options.rotateGesturesEnabled) - mapOptions.scrollGesturesEnabled(options.scrollGesturesEnabled) - mapOptions.tiltGesturesEnabled(options.tiltGesturesEnabled) - mapOptions.zoomGesturesEnabled(options.zoomGesturesEnabled) - mapOptions.scrollGesturesEnabledDuringRotateOrZoom( + googleMapOptions.camera(convertCameraPositionFromDto(options.cameraPosition)) + googleMapOptions.mapType(convertMapTypeFromDto(options.mapType)) + googleMapOptions.compassEnabled(options.compassEnabled) + googleMapOptions.rotateGesturesEnabled(options.rotateGesturesEnabled) + googleMapOptions.scrollGesturesEnabled(options.scrollGesturesEnabled) + googleMapOptions.tiltGesturesEnabled(options.tiltGesturesEnabled) + googleMapOptions.zoomGesturesEnabled(options.zoomGesturesEnabled) + googleMapOptions.scrollGesturesEnabledDuringRotateOrZoom( options.scrollGesturesEnabledDuringRotateOrZoom ) - mapOptions.mapToolbarEnabled(options.mapToolbarEnabled) + googleMapOptions.mapToolbarEnabled(options.mapToolbarEnabled) options.cameraTargetBounds?.let { - mapOptions.latLngBoundsForCameraTarget(convertLatLngBoundsFromDto(it)) + googleMapOptions.latLngBoundsForCameraTarget(convertLatLngBoundsFromDto(it)) } - options.minZoomPreference?.let { mapOptions.minZoomPreference(it.toFloat()) } - options.maxZoomPreference?.let { mapOptions.maxZoomPreference(it.toFloat()) } - mapOptions.zoomControlsEnabled(options.zoomControlsEnabled) + options.minZoomPreference?.let { googleMapOptions.minZoomPreference(it.toFloat()) } + options.maxZoomPreference?.let { googleMapOptions.maxZoomPreference(it.toFloat()) } + googleMapOptions.zoomControlsEnabled(options.zoomControlsEnabled) - return mapOptions + return MapOptions(googleMapOptions, options.padding) } /** 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 b11a2c9..f56131f 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 @@ -18,20 +18,19 @@ package com.google.maps.flutter.navigation import android.content.Context import android.view.View -import com.google.android.gms.maps.GoogleMapOptions import com.google.android.gms.maps.MapView import io.flutter.plugin.platform.PlatformView class GoogleMapView internal constructor( context: Context, - mapOptions: GoogleMapOptions, + mapOptions: MapOptions, viewId: Int, viewEventApi: ViewEventApi, private val viewRegistry: GoogleMapsViewRegistry, imageRegistry: ImageRegistry, ) : PlatformView, GoogleMapsBaseMapView(viewId, mapOptions, viewEventApi, imageRegistry) { - private val _mapView: MapView = MapView(context, mapOptions) + private val _mapView: MapView = MapView(context, mapOptions.googleMapOptions) override fun getView(): View { return _mapView @@ -52,6 +51,7 @@ internal constructor( imageRegistry.mapViewInitializationComplete() mapReady() invalidateViewAfterMapLoad() + mapOptions.padding?.let { setPadding(it) } } } diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoMapView.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoMapView.kt index 4402072..43a65c6 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoMapView.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoMapView.kt @@ -18,12 +18,11 @@ package com.google.maps.flutter.navigation import android.view.View import com.google.android.gms.maps.GoogleMap -import com.google.android.gms.maps.GoogleMapOptions import com.google.android.libraries.navigation.NavigationViewForAuto class GoogleMapsAutoMapView internal constructor( - mapOptions: GoogleMapOptions, + mapOptions: MapOptions, private val viewRegistry: GoogleMapsViewRegistry, imageRegistry: ImageRegistry, private val mapView: NavigationViewForAuto, diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt index 75ce385..576d3c8 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt @@ -25,7 +25,6 @@ import com.google.android.gms.maps.CameraUpdate import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener -import com.google.android.gms.maps.GoogleMapOptions import com.google.android.gms.maps.model.CameraPosition import com.google.android.gms.maps.model.Circle import com.google.android.gms.maps.model.FollowMyLocationOptions @@ -39,7 +38,7 @@ import com.google.android.libraries.navigation.NavigationView abstract class GoogleMapsBaseMapView( protected val viewId: Int?, - mapOptions: GoogleMapOptions, + mapOptions: MapOptions, protected val viewEventApi: ViewEventApi?, private val imageRegistry: ImageRegistry, ) { @@ -100,8 +99,8 @@ abstract class GoogleMapsBaseMapView( } init { - _minZoomLevelPreference = mapOptions.minZoomPreference - _maxZoomLevelPreference = mapOptions.maxZoomPreference + _minZoomLevelPreference = mapOptions.googleMapOptions.minZoomPreference + _maxZoomLevelPreference = mapOptions.googleMapOptions.maxZoomPreference } protected fun mapReady() { 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 d6237e3..f5ae4bd 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 @@ -20,21 +20,20 @@ import android.content.Context import android.content.res.Configuration import android.view.View import com.google.android.gms.maps.CameraUpdateFactory -import com.google.android.gms.maps.GoogleMapOptions import com.google.android.libraries.navigation.NavigationView import io.flutter.plugin.platform.PlatformView class GoogleMapsNavigationView internal constructor( context: Context, - mapOptions: GoogleMapOptions, + mapOptions: MapOptions, navigationOptions: NavigationViewOptions?, viewId: Int, private val viewRegistry: GoogleMapsViewRegistry, viewEventApi: ViewEventApi, private val imageRegistry: ImageRegistry, ) : PlatformView, GoogleMapsBaseMapView(viewId, mapOptions, viewEventApi, imageRegistry) { - private val _navigationView: NavigationView = NavigationView(context, mapOptions) + private val _navigationView: NavigationView = NavigationView(context, mapOptions.googleMapOptions) /// Default values for UI features. private var _isNavigationTripProgressBarEnabled: Boolean = false @@ -79,12 +78,13 @@ internal constructor( // respected. _navigationView.isNavigationUiEnabled = navigationViewEnabled if (!navigationViewEnabled) { - map.moveCamera(CameraUpdateFactory.newCameraPosition(mapOptions.camera)) + map.moveCamera(CameraUpdateFactory.newCameraPosition(mapOptions.googleMapOptions.camera)) } // Call and clear view ready callback if available. mapReady() invalidateViewAfterMapLoad() + mapOptions.padding?.let { setPadding(it) } } } diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/MapOptions.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/MapOptions.kt new file mode 100644 index 0000000..7416974 --- /dev/null +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/MapOptions.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2024 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. + */ + +package com.google.maps.flutter.navigation + +import com.google.android.gms.maps.GoogleMapOptions + +class MapOptions(val googleMapOptions: GoogleMapOptions, val padding: MapPaddingDto?) {} diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt index 108b12f..0e81716 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt @@ -542,6 +542,8 @@ data class MapOptionsDto( * the camera target does not move outside these bounds. */ val cameraTargetBounds: LatLngBoundsDto? = null, + /** Specifies the padding for the map. */ + val padding: MapPaddingDto? = null, ) { companion object { @Suppress("UNCHECKED_CAST") @@ -560,6 +562,7 @@ data class MapOptionsDto( val zoomControlsEnabled = list[11] as Boolean val cameraTargetBounds: LatLngBoundsDto? = (list[12] as List?)?.let { LatLngBoundsDto.fromList(it) } + val padding: MapPaddingDto? = (list[13] as List?)?.let { MapPaddingDto.fromList(it) } return MapOptionsDto( cameraPosition, mapType, @@ -574,6 +577,7 @@ data class MapOptionsDto( maxZoomPreference, zoomControlsEnabled, cameraTargetBounds, + padding, ) } } @@ -593,6 +597,7 @@ data class MapOptionsDto( maxZoomPreference, zoomControlsEnabled, cameraTargetBounds?.toList(), + padding?.toList(), ) } } @@ -1726,9 +1731,12 @@ private object NavigationViewCreationApiCodec : StandardMessageCodec() { return (readValue(buffer) as? List)?.let { MapOptionsDto.fromList(it) } } 132.toByte() -> { - return (readValue(buffer) as? List)?.let { NavigationViewOptionsDto.fromList(it) } + return (readValue(buffer) as? List)?.let { MapPaddingDto.fromList(it) } } 133.toByte() -> { + return (readValue(buffer) as? List)?.let { NavigationViewOptionsDto.fromList(it) } + } + 134.toByte() -> { return (readValue(buffer) as? List)?.let { ViewCreationOptionsDto.fromList(it) } } else -> super.readValueOfType(type, buffer) @@ -1753,14 +1761,18 @@ private object NavigationViewCreationApiCodec : StandardMessageCodec() { stream.write(131) writeValue(stream, value.toList()) } - is NavigationViewOptionsDto -> { + is MapPaddingDto -> { stream.write(132) writeValue(stream, value.toList()) } - is ViewCreationOptionsDto -> { + is NavigationViewOptionsDto -> { stream.write(133) writeValue(stream, value.toList()) } + is ViewCreationOptionsDto -> { + stream.write(134) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } 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 ae3fb01..64d88cf 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,58 +376,76 @@ internal class ConvertTest { val mapOptions = Convert.convertMapOptionsFromDto(testOptions) - assertEquals(mapOptions.camera.target.latitude, testOptions.cameraPosition.target.latitude) + assertEquals( + mapOptions.googleMapOptions.camera.target.latitude, + testOptions.cameraPosition.target.latitude, + ) - assertEquals(mapOptions.camera.target.longitude, testOptions.cameraPosition.target.longitude) + assertEquals( + mapOptions.googleMapOptions.camera.target.longitude, + testOptions.cameraPosition.target.longitude, + ) - assertEquals(mapOptions.camera.bearing, testOptions.cameraPosition.bearing.toFloat()) + assertEquals( + mapOptions.googleMapOptions.camera.bearing, + testOptions.cameraPosition.bearing.toFloat(), + ) - assertEquals(mapOptions.camera.tilt, testOptions.cameraPosition.tilt.toFloat()) + assertEquals(mapOptions.googleMapOptions.camera.tilt, testOptions.cameraPosition.tilt.toFloat()) - assertEquals(mapOptions.camera.zoom, testOptions.cameraPosition.zoom.toFloat()) + assertEquals(mapOptions.googleMapOptions.camera.zoom, testOptions.cameraPosition.zoom.toFloat()) - assertEquals(mapOptions.mapType, GoogleMap.MAP_TYPE_HYBRID) + assertEquals(mapOptions.googleMapOptions.mapType, GoogleMap.MAP_TYPE_HYBRID) - assertEquals(mapOptions.compassEnabled, testOptions.compassEnabled) + assertEquals(mapOptions.googleMapOptions.compassEnabled, testOptions.compassEnabled) - assertEquals(mapOptions.scrollGesturesEnabled, testOptions.scrollGesturesEnabled) + assertEquals( + mapOptions.googleMapOptions.scrollGesturesEnabled, + testOptions.scrollGesturesEnabled, + ) - assertEquals(mapOptions.tiltGesturesEnabled, testOptions.tiltGesturesEnabled) + assertEquals(mapOptions.googleMapOptions.tiltGesturesEnabled, testOptions.tiltGesturesEnabled) - assertEquals(mapOptions.zoomGesturesEnabled, testOptions.zoomGesturesEnabled) + assertEquals(mapOptions.googleMapOptions.zoomGesturesEnabled, testOptions.zoomGesturesEnabled) assertEquals( - mapOptions.scrollGesturesEnabledDuringRotateOrZoom, + mapOptions.googleMapOptions.scrollGesturesEnabledDuringRotateOrZoom, testOptions.scrollGesturesEnabledDuringRotateOrZoom, ) - assertEquals(mapOptions.mapToolbarEnabled, testOptions.mapToolbarEnabled) + assertEquals(mapOptions.googleMapOptions.mapToolbarEnabled, testOptions.mapToolbarEnabled) assertEquals( - mapOptions.latLngBoundsForCameraTarget.northeast.latitude, + mapOptions.googleMapOptions.latLngBoundsForCameraTarget.northeast.latitude, testOptions.cameraTargetBounds?.northeast?.latitude, ) assertEquals( - mapOptions.latLngBoundsForCameraTarget.northeast.longitude, + mapOptions.googleMapOptions.latLngBoundsForCameraTarget.northeast.longitude, testOptions.cameraTargetBounds?.northeast?.longitude, ) assertEquals( - mapOptions.latLngBoundsForCameraTarget.southwest.latitude, + mapOptions.googleMapOptions.latLngBoundsForCameraTarget.southwest.latitude, testOptions.cameraTargetBounds?.southwest?.latitude, ) assertEquals( - mapOptions.latLngBoundsForCameraTarget.southwest.longitude, + mapOptions.googleMapOptions.latLngBoundsForCameraTarget.southwest.longitude, testOptions.cameraTargetBounds?.southwest?.longitude, ) - assertEquals(mapOptions.minZoomPreference, testOptions.minZoomPreference?.toFloat()) + assertEquals( + mapOptions.googleMapOptions.minZoomPreference, + testOptions.minZoomPreference?.toFloat(), + ) - assertEquals(mapOptions.maxZoomPreference, testOptions.maxZoomPreference?.toFloat()) + assertEquals( + mapOptions.googleMapOptions.maxZoomPreference, + testOptions.maxZoomPreference?.toFloat(), + ) - assertEquals(mapOptions.zoomControlsEnabled, testOptions.zoomControlsEnabled) + assertEquals(mapOptions.googleMapOptions.zoomControlsEnabled, testOptions.zoomControlsEnabled) // Test nullable values val testOptions2 = @@ -438,11 +456,11 @@ internal class ConvertTest { ) val mapOptions2 = Convert.convertMapOptionsFromDto(testOptions2) - assertEquals(mapOptions2.minZoomPreference, null) + assertEquals(mapOptions2.googleMapOptions.minZoomPreference, null) - assertEquals(mapOptions2.maxZoomPreference, null) + assertEquals(mapOptions2.googleMapOptions.maxZoomPreference, null) - assertEquals(mapOptions2.latLngBoundsForCameraTarget, null) + assertEquals(mapOptions2.googleMapOptions.latLngBoundsForCameraTarget, null) } @Test diff --git a/example/lib/pages/navigation.dart b/example/lib/pages/navigation.dart index ba792c9..936738c 100644 --- a/example/lib/pages/navigation.dart +++ b/example/lib/pages/navigation.dart @@ -1029,7 +1029,8 @@ class _NavigationPageState extends ExamplePageState { initialNavigationUIEnabledPreference: _guidanceRunning ? NavigationUIEnabledPreference.automatic : NavigationUIEnabledPreference.disabled, - ) + initialPadding: + MapPadding(top: 0, left: 0, bottom: 0, right: 0)) : const Center( child: Column( mainAxisSize: MainAxisSize.min, diff --git a/example/lib/pages/widget_initialization.dart b/example/lib/pages/widget_initialization.dart index 42ed0c3..3f1e2d8 100644 --- a/example/lib/pages/widget_initialization.dart +++ b/example/lib/pages/widget_initialization.dart @@ -49,6 +49,7 @@ class _ViewInitializationPageState double? _initialMaxZoomPreference; bool _initialZoomControlsEnabled = true; LatLngBounds? _initialCameraTargetBounds; + MapPadding? _initialPadding; NavigationUIEnabledPreference _initialNavigationUIEnabledPreference = NavigationUIEnabledPreference.automatic; TextDirection? _layoutDirection; @@ -107,6 +108,7 @@ class _ViewInitializationPageState initialMaxZoomPreference: _initialMaxZoomPreference, initialZoomControlsEnabled: _initialZoomControlsEnabled, initialCameraTargetBounds: _initialCameraTargetBounds, + initialPadding: _initialPadding, initialNavigationUIEnabledPreference: _initialNavigationUIEnabledPreference, layoutDirection: _layoutDirection, @@ -404,6 +406,7 @@ class _InitializedViewPage extends StatelessWidget { required this.initialMaxZoomPreference, required this.initialZoomControlsEnabled, required this.initialCameraTargetBounds, + required this.initialPadding, required this.initialNavigationUIEnabledPreference, required this.layoutDirection, }); @@ -422,6 +425,7 @@ class _InitializedViewPage extends StatelessWidget { final double? initialMaxZoomPreference; final bool initialZoomControlsEnabled; final LatLngBounds? initialCameraTargetBounds; + final MapPadding? initialPadding; final NavigationUIEnabledPreference initialNavigationUIEnabledPreference; @override @@ -453,6 +457,7 @@ class _InitializedViewPage extends StatelessWidget { initialMaxZoomPreference: initialMaxZoomPreference, initialZoomControlsEnabled: initialZoomControlsEnabled, initialCameraTargetBounds: initialCameraTargetBounds, + initialPadding: initialPadding, initialNavigationUIEnabledPreference: initialNavigationUIEnabledPreference, ), diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/Convert+MapConfiguration.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/Convert+MapConfiguration.swift index c2659b7..4d1c256 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/Convert+MapConfiguration.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/Convert+MapConfiguration.swift @@ -48,7 +48,13 @@ extension Convert { scrollGesturesEnabledDuringRotateOrZoom: mapOptions.scrollGesturesEnabledDuringRotateOrZoom, cameraTargetBounds: cameraTargetBounds, minZoomPreference: mapOptions.minZoomPreference.map { Float($0) }, - maxZoomPreference: mapOptions.maxZoomPreference.map { Float($0) } + maxZoomPreference: mapOptions.maxZoomPreference.map { Float($0) }, + padding: UIEdgeInsets( + top: CGFloat(mapOptions.padding?.top ?? 0), + left: CGFloat(mapOptions.padding?.left ?? 0), + bottom: CGFloat(mapOptions.padding?.bottom ?? 0), + right: CGFloat(mapOptions.padding?.right ?? 0) + ) ) } } 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 2e9fa2b..bbc410a 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/MapConfiguration.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/MapConfiguration.swift @@ -37,6 +37,7 @@ struct MapConfiguration { var cameraTargetBounds: GMSCoordinateBounds? var minZoomPreference: Float? var maxZoomPreference: Float? + var padding: UIEdgeInsets? } extension MapConfiguration { @@ -57,6 +58,7 @@ extension MapConfiguration { minZoomPreference ?? kGMSMinZoomLevel, maxZoom: maxZoomPreference ?? kGMSMaxZoomLevel ) + mapView.padding = padding ?? UIEdgeInsets.zero } // Applies the configuration to the given diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift index c6e031a..bb7fbf9 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift @@ -403,6 +403,8 @@ struct MapOptionsDto { /// Specifies a bounds to constrain the camera target, so that when users scroll and pan the map, /// the camera target does not move outside these bounds. var cameraTargetBounds: LatLngBoundsDto? + /// Specifies the padding for the map. + var padding: MapPaddingDto? static func fromList(_ list: [Any?]) -> MapOptionsDto? { let cameraPosition = CameraPositionDto.fromList(list[0] as! [Any?])! @@ -421,6 +423,10 @@ struct MapOptionsDto { if let cameraTargetBoundsList: [Any?] = nilOrValue(list[12]) { cameraTargetBounds = LatLngBoundsDto.fromList(cameraTargetBoundsList) } + var padding: MapPaddingDto? + if let paddingList: [Any?] = nilOrValue(list[13]) { + padding = MapPaddingDto.fromList(paddingList) + } return MapOptionsDto( cameraPosition: cameraPosition, @@ -435,7 +441,8 @@ struct MapOptionsDto { minZoomPreference: minZoomPreference, maxZoomPreference: maxZoomPreference, zoomControlsEnabled: zoomControlsEnabled, - cameraTargetBounds: cameraTargetBounds + cameraTargetBounds: cameraTargetBounds, + padding: padding ) } @@ -454,6 +461,7 @@ struct MapOptionsDto { maxZoomPreference, zoomControlsEnabled, cameraTargetBounds?.toList(), + padding?.toList(), ] } } @@ -1739,8 +1747,10 @@ private class NavigationViewCreationApiCodecReader: FlutterStandardReader { case 131: return MapOptionsDto.fromList(readValue() as! [Any?]) case 132: - return NavigationViewOptionsDto.fromList(readValue() as! [Any?]) + return MapPaddingDto.fromList(readValue() as! [Any?]) case 133: + return NavigationViewOptionsDto.fromList(readValue() as! [Any?]) + case 134: return ViewCreationOptionsDto.fromList(readValue() as! [Any?]) default: return super.readValue(ofType: type) @@ -1762,12 +1772,15 @@ private class NavigationViewCreationApiCodecWriter: FlutterStandardWriter { } else if let value = value as? MapOptionsDto { super.writeByte(131) super.writeValue(value.toList()) - } else if let value = value as? NavigationViewOptionsDto { + } else if let value = value as? MapPaddingDto { super.writeByte(132) super.writeValue(value.toList()) - } else if let value = value as? ViewCreationOptionsDto { + } else if let value = value as? NavigationViewOptionsDto { super.writeByte(133) super.writeValue(value.toList()) + } else if let value = value as? ViewCreationOptionsDto { + super.writeByte(134) + super.writeValue(value.toList()) } else { super.writeValue(value) } diff --git a/lib/src/google_maps_map_view.dart b/lib/src/google_maps_map_view.dart index c29a809..a6114a2 100644 --- a/lib/src/google_maps_map_view.dart +++ b/lib/src/google_maps_map_view.dart @@ -44,6 +44,7 @@ abstract class GoogleMapsBaseMapView extends StatefulWidget { this.initialMaxZoomPreference, this.initialZoomControlsEnabled = true, this.initialCameraTargetBounds, + this.initialPadding, this.layoutDirection, this.gestureRecognizers = const >{}, this.onRecenterButtonClicked, @@ -147,6 +148,11 @@ abstract class GoogleMapsBaseMapView extends StatefulWidget { /// Null by default (unbounded). final LatLngBounds? initialCameraTargetBounds; + /// Specifies the initial padding for the map view. + /// + /// Null by default (no padding). + final MapPadding? initialPadding; + /// Which gestures should be forwarded to the PlatformView. /// /// When this set is empty, the map will only handle pointer events for gestures that @@ -252,6 +258,7 @@ class GoogleMapsMapView extends GoogleMapsBaseMapView { super.initialMaxZoomPreference, super.initialZoomControlsEnabled = true, super.initialCameraTargetBounds, + super.initialPadding, super.layoutDirection, super.gestureRecognizers = const >{}, @@ -377,6 +384,7 @@ class GoogleMapsMapViewState extends MapViewState { maxZoomPreference: widget.initialMaxZoomPreference, zoomControlsEnabled: widget.initialZoomControlsEnabled, cameraTargetBounds: widget.initialCameraTargetBounds, + padding: widget.initialPadding, ), ), onMapReady: _onPlatformViewCreated); diff --git a/lib/src/google_maps_navigation_view.dart b/lib/src/google_maps_navigation_view.dart index f68ac66..9624e59 100644 --- a/lib/src/google_maps_navigation_view.dart +++ b/lib/src/google_maps_navigation_view.dart @@ -60,6 +60,7 @@ class GoogleMapsNavigationView extends GoogleMapsBaseMapView { super.initialMaxZoomPreference, super.initialZoomControlsEnabled = true, super.initialCameraTargetBounds, + super.initialPadding, this.initialNavigationUIEnabledPreference = NavigationUIEnabledPreference.automatic, super.layoutDirection, @@ -140,6 +141,7 @@ class GoogleMapsNavigationViewState maxZoomPreference: widget.initialMaxZoomPreference, zoomControlsEnabled: widget.initialZoomControlsEnabled, cameraTargetBounds: widget.initialCameraTargetBounds, + padding: widget.initialPadding, ), navigationViewOptions: NavigationViewOptions( navigationUIEnabledPreference: diff --git a/lib/src/method_channel/common_view_api.dart b/lib/src/method_channel/common_view_api.dart index 5e79b48..3aa0f62 100644 --- a/lib/src/method_channel/common_view_api.dart +++ b/lib/src/method_channel/common_view_api.dart @@ -106,7 +106,8 @@ mixin CommonMapViewAPI on MapViewAPIInterface { minZoomPreference: mapOptions.minZoomPreference, maxZoomPreference: mapOptions.maxZoomPreference, zoomControlsEnabled: mapOptions.zoomControlsEnabled, - cameraTargetBounds: mapOptions.cameraTargetBounds?.toDto()); + cameraTargetBounds: mapOptions.cameraTargetBounds?.toDto(), + padding: mapOptions.padding?.toDto()); // Initialize navigation view options if given NavigationViewOptionsDto? navigationOptionsMessage; diff --git a/lib/src/method_channel/convert/convert.dart b/lib/src/method_channel/convert/convert.dart index 49590f7..5c74e04 100644 --- a/lib/src/method_channel/convert/convert.dart +++ b/lib/src/method_channel/convert/convert.dart @@ -19,6 +19,7 @@ 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 new file mode 100644 index 0000000..767a654 --- /dev/null +++ b/lib/src/method_channel/convert/map_padding.dart @@ -0,0 +1,25 @@ +// 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/method_channel/messages.g.dart b/lib/src/method_channel/messages.g.dart index 9576b7e..d6f88c3 100644 --- a/lib/src/method_channel/messages.g.dart +++ b/lib/src/method_channel/messages.g.dart @@ -446,6 +446,7 @@ class MapOptionsDto { this.maxZoomPreference, required this.zoomControlsEnabled, this.cameraTargetBounds, + this.padding, }); /// The initial positioning of the camera in the map view. @@ -488,6 +489,9 @@ class MapOptionsDto { /// the camera target does not move outside these bounds. LatLngBoundsDto? cameraTargetBounds; + /// Specifies the padding for the map. + MapPaddingDto? padding; + Object encode() { return [ cameraPosition.encode(), @@ -503,6 +507,7 @@ class MapOptionsDto { maxZoomPreference, zoomControlsEnabled, cameraTargetBounds?.encode(), + padding?.encode(), ]; } @@ -524,6 +529,9 @@ class MapOptionsDto { cameraTargetBounds: result[12] != null ? LatLngBoundsDto.decode(result[12]! as List) : null, + padding: result[13] != null + ? MapPaddingDto.decode(result[13]! as List) + : null, ); } } @@ -1960,12 +1968,15 @@ class _NavigationViewCreationApiCodec extends StandardMessageCodec { } else if (value is MapOptionsDto) { buffer.putUint8(131); writeValue(buffer, value.encode()); - } else if (value is NavigationViewOptionsDto) { + } else if (value is MapPaddingDto) { buffer.putUint8(132); writeValue(buffer, value.encode()); - } else if (value is ViewCreationOptionsDto) { + } else if (value is NavigationViewOptionsDto) { buffer.putUint8(133); writeValue(buffer, value.encode()); + } else if (value is ViewCreationOptionsDto) { + buffer.putUint8(134); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -1983,8 +1994,10 @@ class _NavigationViewCreationApiCodec extends StandardMessageCodec { case 131: return MapOptionsDto.decode(readValue(buffer)!); case 132: - return NavigationViewOptionsDto.decode(readValue(buffer)!); + return MapPaddingDto.decode(readValue(buffer)!); case 133: + return NavigationViewOptionsDto.decode(readValue(buffer)!); + case 134: return ViewCreationOptionsDto.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); diff --git a/lib/src/types/view_initialization_options.dart b/lib/src/types/view_initialization_options.dart index 21b8c5e..a3fac44 100644 --- a/lib/src/types/view_initialization_options.dart +++ b/lib/src/types/view_initialization_options.dart @@ -100,6 +100,7 @@ class MapOptions { this.maxZoomPreference, this.zoomControlsEnabled = true, this.cameraTargetBounds, + this.padding, }) : assert( minZoomPreference == null || maxZoomPreference == null || @@ -183,6 +184,11 @@ class MapOptions { /// /// Null by default (unbounded). final LatLngBounds? cameraTargetBounds; + + /// Specifies the initial padding for the map view. + /// + /// Null by default (no padding). + final MapPadding? padding; } /// Determines the initial visibility of the navigation UI on map initialization. diff --git a/pigeons/messages.dart b/pigeons/messages.dart index 244edd0..d5919d3 100644 --- a/pigeons/messages.dart +++ b/pigeons/messages.dart @@ -53,6 +53,7 @@ class MapOptionsDto { required this.maxZoomPreference, required this.zoomControlsEnabled, required this.cameraTargetBounds, + required this.padding, }); /// The initial positioning of the camera in the map view. @@ -94,6 +95,9 @@ class MapOptionsDto { /// Specifies a bounds to constrain the camera target, so that when users scroll and pan the map, /// the camera target does not move outside these bounds. final LatLngBoundsDto? cameraTargetBounds; + + /// Specifies the padding for the map. + final MapPaddingDto? padding; } /// Determines the initial visibility of the navigation UI on map initialization. From 111b215d8ec2f717c77afdff576712f6e4a378f7 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 3/7] 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 f56131f..0b946ea 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 @@ -50,8 +50,8 @@ internal constructor( initListeners() imageRegistry.mapViewInitializationComplete() mapReady() - invalidateViewAfterMapLoad() mapOptions.padding?.let { setPadding(it) } + invalidateViewAfterMapLoad() } } 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 f5ae4bd..7d51ef7 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 @@ -83,8 +83,8 @@ internal constructor( // Call and clear view ready callback if available. mapReady() - invalidateViewAfterMapLoad() mapOptions.padding?.let { setPadding(it) } + invalidateViewAfterMapLoad() } } 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. From 8b374cc61f19deb6d6dbcb04f725a07a81d2560f Mon Sep 17 00:00:00 2001 From: Joonas Kerttula Date: Tue, 10 Dec 2024 10:53:28 +0200 Subject: [PATCH 4/7] chore: format --- .../maps/flutter/navigation/ConvertTest.kt | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) 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 16e6083..64d88cf 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,11 +376,20 @@ 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()) @@ -390,7 +399,10 @@ 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) @@ -423,9 +435,15 @@ 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) From 26e527c747e5b8162fce8e03e2a5cb305a889d04 Mon Sep 17 00:00:00 2001 From: Joonas Kerttula Date: Tue, 10 Dec 2024 11:14:47 +0200 Subject: [PATCH 5/7] chore: fix padding value presentation on example app --- example/lib/pages/navigation.dart | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/example/lib/pages/navigation.dart b/example/lib/pages/navigation.dart index 825d273..2f94f67 100644 --- a/example/lib/pages/navigation.dart +++ b/example/lib/pages/navigation.dart @@ -1501,13 +1501,14 @@ class _NavigationPageState extends ExamplePageState { _trafficIndicentCardsEnabled = newValue; }); }), - Text('Map left padding: ${_mapPadding.left}'), + Text( + 'Map left padding: ${_mapPadding.left.toStringAsFixed(0)}'), Slider( value: _mapPadding.left.toDouble(), min: 0, max: 200, divisions: 20, - label: _mapPadding.left.toString(), + label: _mapPadding.left.toStringAsFixed(0), onChanged: (double value) { _setPadding(EdgeInsets.only( top: _mapPadding.top, @@ -1515,13 +1516,14 @@ class _NavigationPageState extends ExamplePageState { bottom: _mapPadding.bottom, right: _mapPadding.right)); }), - Text('Map right padding: ${_mapPadding.right}'), + Text( + 'Map right padding: ${_mapPadding.right.toStringAsFixed(0)}'), Slider( value: _mapPadding.right.toDouble(), min: 0, max: 200, divisions: 20, - label: _mapPadding.right.toString(), + label: _mapPadding.right.toStringAsFixed(0), onChanged: (double value) { _setPadding(EdgeInsets.only( top: _mapPadding.top, @@ -1529,13 +1531,14 @@ class _NavigationPageState extends ExamplePageState { bottom: _mapPadding.bottom, right: value)); }), - Text('Map top padding: ${_mapPadding.top}'), + Text( + 'Map top padding: ${_mapPadding.top.toStringAsFixed(0)}'), Slider( value: _mapPadding.top.toDouble(), min: 0, max: 200, divisions: 20, - label: _mapPadding.top.toString(), + label: _mapPadding.top.toStringAsFixed(0), onChanged: (double value) { _setPadding(EdgeInsets.only( top: value, @@ -1543,13 +1546,14 @@ class _NavigationPageState extends ExamplePageState { bottom: _mapPadding.bottom, right: _mapPadding.right)); }), - Text('Map bottom padding: ${_mapPadding.bottom}'), + Text( + 'Map bottom padding: ${_mapPadding.bottom.toStringAsFixed(0)}'), Slider( value: _mapPadding.bottom.toDouble(), min: 0, max: 200, divisions: 20, - label: _mapPadding.bottom.toString(), + label: _mapPadding.bottom.toStringAsFixed(0), onChanged: (double value) { _setPadding(EdgeInsets.only( top: _mapPadding.top, From cf2fcf1ef547012c632e9febc3b20e589df53abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4limaa?= Date: Mon, 16 Dec 2024 17:49:37 +0800 Subject: [PATCH 6/7] feat: add get padding --- .../GoogleMapsAutoViewMessageHandler.kt | 4 ++ .../navigation/GoogleMapsBaseMapView.kt | 8 +++ .../GoogleMapsViewMessageHandler.kt | 4 ++ .../maps/flutter/navigation/MapOptions.kt | 2 +- .../maps/flutter/navigation/messages.g.kt | 48 +++++++++++++++ .../GoogleMapsAutoViewMessageHandler.swift | 4 ++ .../GoogleMapsNavigationView.swift | 9 +++ ...ogleMapsNavigationViewMessageHandler.swift | 4 ++ .../messages.g.swift | 38 ++++++++++++ lib/src/google_maps_auto_view_controller.dart | 5 ++ lib/src/google_maps_map_view_controller.dart | 5 ++ ...navigation_flutter_platform_interface.dart | 6 ++ .../method_channel/common_auto_view_api.dart | 11 ++++ lib/src/method_channel/common_view_api.dart | 11 ++++ lib/src/method_channel/messages.g.dart | 58 +++++++++++++++++++ pigeons/messages.dart | 2 + test/messages_test.g.dart | 33 +++++++++++ 17 files changed, 251 insertions(+), 1 deletion(-) diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoViewMessageHandler.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoViewMessageHandler.kt index 0cf191b..a1baaee 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoViewMessageHandler.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsAutoViewMessageHandler.kt @@ -389,4 +389,8 @@ class GoogleMapsAutoViewMessageHandler(private val viewRegistry: GoogleMapsViewR override fun setPadding(padding: MapPaddingDto) { getView().setPadding(padding) } + + override fun getPadding(): MapPaddingDto { + return getView().getPadding() + } } diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt index 576d3c8..27d05ce 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsBaseMapView.kt @@ -58,6 +58,8 @@ abstract class GoogleMapsBaseMapView( private var _minZoomLevelPreference: Float? = null private var _maxZoomLevelPreference: Float? = null + private var _mapOptions: MapOptions? = null + // Nullable variable to hold the callback function private var _mapReadyCallback: ((Result) -> Unit)? = null private var _loadedCallbackPending = false @@ -101,6 +103,7 @@ abstract class GoogleMapsBaseMapView( init { _minZoomLevelPreference = mapOptions.googleMapOptions.minZoomPreference _maxZoomLevelPreference = mapOptions.googleMapOptions.maxZoomPreference + _mapOptions = mapOptions } protected fun mapReady() { @@ -943,6 +946,7 @@ abstract class GoogleMapsBaseMapView( } fun setPadding(padding: MapPaddingDto) { + _mapOptions?.padding = padding getMap() .setPadding( padding.left.toInt(), @@ -951,4 +955,8 @@ abstract class GoogleMapsBaseMapView( padding.bottom.toInt(), ) } + + fun getPadding(): MapPaddingDto { + return _mapOptions?.padding ?: MapPaddingDto(0, 0, 0, 0) + } } diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsViewMessageHandler.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsViewMessageHandler.kt index 98cab2b..13dd436 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsViewMessageHandler.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsViewMessageHandler.kt @@ -479,4 +479,8 @@ class GoogleMapsViewMessageHandler(private val viewRegistry: GoogleMapsViewRegis override fun setPadding(viewId: Long, padding: MapPaddingDto) { getView(viewId.toInt()).setPadding(padding) } + + override fun getPadding(viewId: Long): MapPaddingDto { + return getView(viewId.toInt()).getPadding() + } } diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/MapOptions.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/MapOptions.kt index 7416974..562665b 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/MapOptions.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/MapOptions.kt @@ -18,4 +18,4 @@ package com.google.maps.flutter.navigation import com.google.android.gms.maps.GoogleMapOptions -class MapOptions(val googleMapOptions: GoogleMapOptions, val padding: MapPaddingDto?) {} +class MapOptions(val googleMapOptions: GoogleMapOptions, var padding: MapPaddingDto?) {} diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt index 0e81716..71014ec 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt @@ -2206,6 +2206,8 @@ interface MapViewApi { fun setPadding(viewId: Long, padding: MapPaddingDto) + fun getPadding(viewId: Long): MapPaddingDto + companion object { /** The codec used by MapViewApi. */ val codec: MessageCodec by lazy { MapViewApiCodec } @@ -4441,6 +4443,29 @@ interface MapViewApi { channel.setMessageHandler(null) } } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.google_navigation_flutter.MapViewApi.getPadding", + codec, + ) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val viewIdArg = args[0].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + wrapped = listOf(api.getPadding(viewIdArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } } } } @@ -6485,6 +6510,8 @@ interface AutoMapViewApi { fun setPadding(padding: MapPaddingDto) + fun getPadding(): MapPaddingDto + companion object { /** The codec used by AutoMapViewApi. */ val codec: MessageCodec by lazy { AutoMapViewApiCodec } @@ -8207,6 +8234,27 @@ interface AutoMapViewApi { channel.setMessageHandler(null) } } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.google_navigation_flutter.AutoMapViewApi.getPadding", + codec, + ) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped: List + try { + wrapped = listOf(api.getPadding()) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } } } } diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsAutoViewMessageHandler.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsAutoViewMessageHandler.swift index 9169d39..576061d 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsAutoViewMessageHandler.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsAutoViewMessageHandler.swift @@ -445,4 +445,8 @@ class GoogleMapsAutoViewMessageHandler: AutoMapViewApi { func setPadding(padding: MapPaddingDto) throws { try getView().setPadding(padding: padding) } + + func getPadding() throws -> MapPaddingDto { + try getView().getPadding() + } } diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift index 1707ef5..6ae60a1 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift @@ -834,6 +834,15 @@ public class GoogleMapsNavigationView: NSObject, FlutterPlatformView, ViewSettle right: CGFloat(padding.right) ) } + + func getPadding() throws -> MapPaddingDto { + MapPaddingDto( + top: Int64(_mapView.padding.top), + left: Int64(_mapView.padding.left), + bottom: Int64(_mapView.padding.bottom), + right: Int64(_mapView.padding.right) + ) + } } extension GoogleMapsNavigationView: GMSMapViewNavigationUIDelegate { diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewMessageHandler.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewMessageHandler.swift index f4269a0..ac5e7ab 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewMessageHandler.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewMessageHandler.swift @@ -509,4 +509,8 @@ class GoogleMapsNavigationViewMessageHandler: MapViewApi { func setPadding(viewId: Int64, padding: MapPaddingDto) throws { try getView(viewId).setPadding(padding: padding) } + + func getPadding(viewId: Int64) throws -> MapPaddingDto { + try getView(viewId).getPadding() + } } diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift index bb7fbf9..0a7ccf1 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift @@ -2075,6 +2075,7 @@ protocol MapViewApi { func clearCircles(viewId: Int64) throws func registerOnCameraChangedListener(viewId: Int64) throws func setPadding(viewId: Int64, padding: MapPaddingDto) throws + func getPadding(viewId: Int64) throws -> MapPaddingDto } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -3952,6 +3953,25 @@ enum MapViewApiSetup { } else { setPaddingChannel.setMessageHandler(nil) } + let getPaddingChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.google_navigation_flutter.MapViewApi.getPadding", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + getPaddingChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let viewIdArg = args[0] is Int64 ? args[0] as! Int64 : Int64(args[0] as! Int32) + do { + let result = try api.getPadding(viewId: viewIdArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getPaddingChannel.setMessageHandler(nil) + } } } @@ -5893,6 +5913,7 @@ protocol AutoMapViewApi { func registerOnCameraChangedListener() throws func isAutoScreenAvailable() throws -> Bool func setPadding(padding: MapPaddingDto) throws + func getPadding() throws -> MapPaddingDto } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -7303,6 +7324,23 @@ enum AutoMapViewApiSetup { } else { setPaddingChannel.setMessageHandler(nil) } + let getPaddingChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.google_navigation_flutter.AutoMapViewApi.getPadding", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + getPaddingChannel.setMessageHandler { _, reply in + do { + let result = try api.getPadding() + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getPaddingChannel.setMessageHandler(nil) + } } } diff --git a/lib/src/google_maps_auto_view_controller.dart b/lib/src/google_maps_auto_view_controller.dart index d69cae1..5f7101b 100644 --- a/lib/src/google_maps_auto_view_controller.dart +++ b/lib/src/google_maps_auto_view_controller.dart @@ -333,6 +333,11 @@ class GoogleMapsAutoViewController { .setPaddingForAuto(padding: padding); } + // Gets the map padding from the map view. + Future getPadding({required int viewId}) async { + return GoogleMapsNavigationPlatform.instance.getPaddingForAuto(); + } + Future isAutoScreenAvailable() { return GoogleMapsNavigationPlatform.instance.isAutoScreenAvailable(); } diff --git a/lib/src/google_maps_map_view_controller.dart b/lib/src/google_maps_map_view_controller.dart index 187d93d..280f13b 100644 --- a/lib/src/google_maps_map_view_controller.dart +++ b/lib/src/google_maps_map_view_controller.dart @@ -371,4 +371,9 @@ class GoogleMapViewController { return GoogleMapsNavigationPlatform.instance .setPadding(viewId: _viewId, padding: padding); } + + // Gets the map padding from the map view. + Future getPadding({required int viewId}) async { + return GoogleMapsNavigationPlatform.instance.getPadding(viewId: _viewId); + } } diff --git a/lib/src/google_navigation_flutter_platform_interface.dart b/lib/src/google_navigation_flutter_platform_interface.dart index c47d917..8d215b6 100644 --- a/lib/src/google_navigation_flutter_platform_interface.dart +++ b/lib/src/google_navigation_flutter_platform_interface.dart @@ -535,6 +535,9 @@ abstract mixin class MapViewAPIInterface { // Sets the map padding for the map view. Future setPadding({required int viewId, required EdgeInsets padding}); + // Gets the map padding from the map view. + Future getPadding({required int viewId}); + /// Get navigation view marker event stream from the navigation view. Stream getMarkerEventStream({required int viewId}); @@ -775,6 +778,9 @@ abstract mixin class AutoMapViewAPIInterface { // Sets the map padding for the auto map view. Future setPaddingForAuto({required EdgeInsets padding}); + // Gets the map padding from the auto map view. + Future getPaddingForAuto(); + /// 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 9d5fb75..6acbe84 100644 --- a/lib/src/method_channel/common_auto_view_api.dart +++ b/lib/src/method_channel/common_auto_view_api.dart @@ -745,6 +745,17 @@ mixin CommonAutoMapViewAPI on AutoMapViewAPIInterface { right: padding.right.toInt())); } + // Gets the map padding from the map view. + @override + Future getPaddingForAuto() async { + final MapPaddingDto padding = await _viewApi.getPadding(); + return EdgeInsets.only( + top: padding.top.toDouble(), + left: padding.left.toDouble(), + bottom: padding.bottom.toDouble(), + right: padding.right.toDouble()); + } + @override Future isAutoScreenAvailable() { return _viewApi.isAutoScreenAvailable(); diff --git a/lib/src/method_channel/common_view_api.dart b/lib/src/method_channel/common_view_api.dart index 31149ef..8f16d62 100644 --- a/lib/src/method_channel/common_view_api.dart +++ b/lib/src/method_channel/common_view_api.dart @@ -954,6 +954,17 @@ mixin CommonMapViewAPI on MapViewAPIInterface { right: padding.right.toInt())); } + // Gets the map padding from the map view. + @override + Future getPadding({required int viewId}) async { + final MapPaddingDto padding = await _viewApi.getPadding(viewId); + return EdgeInsets.only( + top: padding.top.toDouble(), + left: padding.left.toDouble(), + bottom: padding.bottom.toDouble(), + right: padding.right.toDouble()); + } + @override Stream getMapClickEventStream({required int viewId}) { return _unwrapEventStream(viewId: viewId); diff --git a/lib/src/method_channel/messages.g.dart b/lib/src/method_channel/messages.g.dart index d6f88c3..529abc5 100644 --- a/lib/src/method_channel/messages.g.dart +++ b/lib/src/method_channel/messages.g.dart @@ -4606,6 +4606,35 @@ class MapViewApi { return; } } + + Future getPadding(int viewId) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.google_navigation_flutter.MapViewApi.getPadding'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([viewId]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as MapPaddingDto?)!; + } + } } class _ImageRegistryApiCodec extends StandardMessageCodec { @@ -8682,6 +8711,35 @@ class AutoMapViewApi { return; } } + + Future getPadding() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.google_navigation_flutter.AutoMapViewApi.getPadding'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as MapPaddingDto?)!; + } + } } class _AutoViewEventApiCodec extends StandardMessageCodec { diff --git a/pigeons/messages.dart b/pigeons/messages.dart index d5919d3..a7c7ac4 100644 --- a/pigeons/messages.dart +++ b/pigeons/messages.dart @@ -516,6 +516,7 @@ abstract class MapViewApi { void registerOnCameraChangedListener(int viewId); void setPadding(int viewId, MapPaddingDto padding); + MapPaddingDto getPadding(int viewId); } @HostApi(dartHostTestHandler: 'TestImageRegistryApi') @@ -1371,6 +1372,7 @@ abstract class AutoMapViewApi { void registerOnCameraChangedListener(); bool isAutoScreenAvailable(); void setPadding(MapPaddingDto padding); + MapPaddingDto getPadding(); } @FlutterApi() diff --git a/test/messages_test.g.dart b/test/messages_test.g.dart index 4d085ac..8f54c95 100644 --- a/test/messages_test.g.dart +++ b/test/messages_test.g.dart @@ -339,6 +339,8 @@ abstract class TestMapViewApi { void setPadding(int viewId, MapPaddingDto padding); + MapPaddingDto getPadding(int viewId); + static void setup(TestMapViewApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel __pigeon_channel = BasicMessageChannel< @@ -3387,6 +3389,37 @@ abstract class TestMapViewApi { }); } } + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.google_navigation_flutter.MapViewApi.getPadding', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, + (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.google_navigation_flutter.MapViewApi.getPadding was null.'); + final List args = (message as List?)!; + final int? arg_viewId = (args[0] as int?); + assert(arg_viewId != null, + 'Argument for dev.flutter.pigeon.google_navigation_flutter.MapViewApi.getPadding was null, expected non-null int.'); + try { + final MapPaddingDto output = api.getPadding(arg_viewId!); + return [output]; + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } } } From 5b59f0e24f98c94259d32e16b4bd1b3b07125929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4limaa?= Date: Mon, 16 Dec 2024 19:55:10 +0800 Subject: [PATCH 7/7] test: padding integration test --- example/integration_test/t06_map_test.dart | 66 +++++++++++++++++++ lib/src/google_maps_auto_view_controller.dart | 2 +- lib/src/google_maps_map_view_controller.dart | 2 +- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/example/integration_test/t06_map_test.dart b/example/integration_test/t06_map_test.dart index a556a08..707e6a7 100644 --- a/example/integration_test/t06_map_test.dart +++ b/example/integration_test/t06_map_test.dart @@ -373,4 +373,70 @@ void main() { }, variant: mapTypeVariants, ); + + patrol( + 'Test map padding', + (PatrolIntegrationTester $) async { + /// For some reason the functionality works on Android example app, but it doesn't work + /// during the testing. Will skip Android testing for now. + final Completer viewControllerCompleter = + Completer(); + + await checkLocationDialogAcceptance($); + + switch (mapTypeVariants.currentValue!) { + case TestMapType.mapView: + + /// Display map view. + final Key key = GlobalKey(); + await pumpMapView( + $, + GoogleMapsMapView( + key: key, + onViewCreated: (GoogleMapViewController controller) { + viewControllerCompleter.complete(controller); + }, + ), + ); + break; + case TestMapType.navigationView: + + /// Display navigation view. + final Key key = GlobalKey(); + await pumpNavigationView( + $, + GoogleMapsNavigationView( + key: key, + onViewCreated: (GoogleNavigationViewController controller) { + viewControllerCompleter.complete(controller); + }, + ), + ); + break; + } + + final GoogleMapViewController viewController = + await viewControllerCompleter.future; + + // Test initial values + EdgeInsets initialPadding = await viewController.getPadding(); + + expect(initialPadding.left, 0.0); + expect(initialPadding.top, 0.0); + expect(initialPadding.right, 0.0); + expect(initialPadding.bottom, 0.0); + + await viewController.setPadding( + const EdgeInsets.only(left: 50, top: 60, right: 70, bottom: 80)); + + // Test that the padding values were changed. + EdgeInsets newPadding = await viewController.getPadding(); + + expect(newPadding.left, 50.0); + expect(newPadding.top, 60.0); + expect(newPadding.right, 70.0); + expect(newPadding.bottom, 80.0); + }, + variant: mapTypeVariants, + ); } diff --git a/lib/src/google_maps_auto_view_controller.dart b/lib/src/google_maps_auto_view_controller.dart index 5f7101b..0ddd05d 100644 --- a/lib/src/google_maps_auto_view_controller.dart +++ b/lib/src/google_maps_auto_view_controller.dart @@ -334,7 +334,7 @@ class GoogleMapsAutoViewController { } // Gets the map padding from the map view. - Future getPadding({required int viewId}) async { + Future getPadding() async { return GoogleMapsNavigationPlatform.instance.getPaddingForAuto(); } diff --git a/lib/src/google_maps_map_view_controller.dart b/lib/src/google_maps_map_view_controller.dart index 280f13b..ce638a2 100644 --- a/lib/src/google_maps_map_view_controller.dart +++ b/lib/src/google_maps_map_view_controller.dart @@ -373,7 +373,7 @@ class GoogleMapViewController { } // Gets the map padding from the map view. - Future getPadding({required int viewId}) async { + Future getPadding() async { return GoogleMapsNavigationPlatform.instance.getPadding(viewId: _viewId); } }