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())); + } + }); + } + } } }