diff --git a/CHANGELOG.md b/CHANGELOG.md index be5d8b1..a8abe46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,12 @@ # Changelog -## 1.2.1 -* Fix Fatal error: Attempted to read an unowned reference but the object was already deallocated ## 1.3.0 * Animate marker position changes instead of removing and re-adding +* Fix Fatal error: Attempted to read an unowned reference but the object was already deallocated +* Fixed an issue where onCameraMove was not invoked by double-tapping +* Added insetsLayoutMarginsFromSafeArea + ## 1.2.0 * Added a `markerAnnotationWithHue()` and `pinAnnotationWithHue()` method to allow custom marker/pin colors diff --git a/example/lib/scrolling_map.dart b/example/lib/scrolling_map.dart index 54c4fef..4b6143a 100644 --- a/example/lib/scrolling_map.dart +++ b/example/lib/scrolling_map.dart @@ -29,6 +29,7 @@ class ScrollingMapBody extends StatelessWidget { @override Widget build(BuildContext context) { return SafeArea( + bottom: false, child: ListView( children: [ Card( @@ -99,6 +100,7 @@ class ScrollingMapBody extends StatelessWidget { () => ScaleGestureRecognizer(), ), ].toSet(), + insetsLayoutMarginsFromSafeArea: false, ), ), ), diff --git a/ios/Classes/MapView/AppleMapController.swift b/ios/Classes/MapView/AppleMapController.swift index 9d750e0..85e7a98 100644 --- a/ios/Classes/MapView/AppleMapController.swift +++ b/ios/Classes/MapView/AppleMapController.swift @@ -9,6 +9,7 @@ import Foundation import MapKit public class AppleMapController: NSObject, FlutterPlatformView { + var contentView: UIView var mapView: FlutterMapView var registrar: FlutterPluginRegistrar var channel: FlutterMethodChannel @@ -25,6 +26,11 @@ public class AppleMapController: NSObject, FlutterPlatformView { self.mapView = FlutterMapView(channel: channel, options: options) self.registrar = registrar + // To stop the odd movement of the Apple logo. + self.contentView = UIScrollView() + self.contentView.addSubview(mapView) + mapView.autoresizingMask = [.flexibleHeight, .flexibleWidth] + self.initialCameraPosition = args["initialCameraPosition"]! as! Dictionary super.init() @@ -49,7 +55,7 @@ public class AppleMapController: NSObject, FlutterPlatformView { } public func view() -> UIView { - return mapView + return contentView } private func setMethodCallHandlers() { diff --git a/ios/Classes/MapView/FlutterMapView.swift b/ios/Classes/MapView/FlutterMapView.swift index 628d533..1e733ed 100644 --- a/ios/Classes/MapView/FlutterMapView.swift +++ b/ios/Classes/MapView/FlutterMapView.swift @@ -194,6 +194,13 @@ class FlutterMapView: MKMapView, UIGestureRecognizerDelegate { self.maxZoomLevel = _maxZoom } } + + if let insetsSafeArea: Bool = options["insetsLayoutMarginsFromSafeArea"] as? Bool { + if #available(iOS 11.0, *) { + self.insetsLayoutMarginsFromSafeArea = insetsSafeArea + } + } + } func setUserLocation() { diff --git a/lib/src/apple_map.dart b/lib/src/apple_map.dart index 5ca5191..793a269 100644 --- a/lib/src/apple_map.dart +++ b/lib/src/apple_map.dart @@ -42,6 +42,7 @@ class AppleMap extends StatefulWidget { this.onTap, this.onLongPress, this.snapshotOptions, + this.insetsLayoutMarginsFromSafeArea = true, }) : super(key: key); final MapCreatedCallback? onMapCreated; @@ -165,6 +166,10 @@ class AppleMap extends StatefulWidget { final SnapshotOptions? snapshotOptions; + /// A Boolean value indicating whether the view's layout margins are updated + /// automatically to reflect the safe area. + final bool insetsLayoutMarginsFromSafeArea; + @override State createState() => _AppleMapState(); } @@ -336,6 +341,7 @@ class _AppleMapOptions { this.myLocationEnabled, this.myLocationButtonEnabled, this.padding, + this.insetsLayoutMarginsFromSafeArea, }); static _AppleMapOptions fromWidget(AppleMap map) { @@ -352,6 +358,7 @@ class _AppleMapOptions { myLocationEnabled: map.myLocationEnabled, myLocationButtonEnabled: map.myLocationButtonEnabled, padding: map.padding, + insetsLayoutMarginsFromSafeArea: map.insetsLayoutMarginsFromSafeArea, ); } @@ -379,6 +386,8 @@ class _AppleMapOptions { final EdgeInsets? padding; + final bool? insetsLayoutMarginsFromSafeArea; + Map toMap() { final Map optionsMap = {}; @@ -400,6 +409,8 @@ class _AppleMapOptions { addIfNonNull('myLocationEnabled', myLocationEnabled); addIfNonNull('myLocationButtonEnabled', myLocationButtonEnabled); addIfNonNull('padding', _serializePadding(padding)); + addIfNonNull( + 'insetsLayoutMarginsFromSafeArea', insetsLayoutMarginsFromSafeArea); return optionsMap; }