From ed945825608490492dd10c6aa314363864d5b377 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 1 Dec 2022 10:28:59 -0500 Subject: [PATCH 1/8] feat: add colorScheme parameter --- ios/Classes/MapView/FlutterMapView.swift | 9 +++++++++ lib/src/apple_map.dart | 9 +++++++++ lib/src/ui.dart | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/ios/Classes/MapView/FlutterMapView.swift b/ios/Classes/MapView/FlutterMapView.swift index 628d533..05d41a3 100644 --- a/ios/Classes/MapView/FlutterMapView.swift +++ b/ios/Classes/MapView/FlutterMapView.swift @@ -20,6 +20,7 @@ class FlutterMapView: MKMapView, UIGestureRecognizerDelegate { var oldBounds: CGRect? var options: Dictionary? var isMyLocationButtonShowing: Bool? = false + var mapStyle: Int? = 0 fileprivate let locationManager: CLLocationManager = CLLocationManager() @@ -144,6 +145,14 @@ class FlutterMapView: MKMapView, UIGestureRecognizerDelegate { if let mapType: Int = options["mapType"] as? Int { self.mapType = self.mapTypes[mapType] } + + if let mapStyle: Int = options["mapStyle"] as? Int { + if #available(iOS 13.0, *) { + if mapStyle != 0 { + self.overrideUserInterfaceStyle = UIUserInterfaceStyle(rawValue: mapStyle) ?? .unspecified + } + } + } if let trafficEnabled: Bool = options["trafficEnabled"] as? Bool { if #available(iOS 9.0, *) { diff --git a/lib/src/apple_map.dart b/lib/src/apple_map.dart index 5ca5191..0f186de 100644 --- a/lib/src/apple_map.dart +++ b/lib/src/apple_map.dart @@ -23,6 +23,7 @@ class AppleMap extends StatefulWidget { this.compassEnabled = true, this.trafficEnabled = false, this.mapType = MapType.standard, + this.mapStyle = MapStyle.system, this.minMaxZoomPreference = MinMaxZoomPreference.unbounded, this.trackingMode = TrackingMode.none, this.rotateGesturesEnabled = true, @@ -58,6 +59,9 @@ class AppleMap extends StatefulWidget { /// Type of map tiles to be rendered. final MapType mapType; + /// TODO + final MapStyle mapStyle; + /// The mode used to track the user location. final TrackingMode trackingMode; @@ -327,6 +331,7 @@ class _AppleMapOptions { this.compassEnabled, this.trafficEnabled, this.mapType, + this.mapStyle, this.minMaxZoomPreference, this.rotateGesturesEnabled, this.scrollGesturesEnabled, @@ -343,6 +348,7 @@ class _AppleMapOptions { compassEnabled: map.compassEnabled, trafficEnabled: map.trafficEnabled, mapType: map.mapType, + mapStyle: map.mapStyle, minMaxZoomPreference: map.minMaxZoomPreference, rotateGesturesEnabled: map.rotateGesturesEnabled, scrollGesturesEnabled: map.scrollGesturesEnabled, @@ -361,6 +367,8 @@ class _AppleMapOptions { final MapType? mapType; + final MapStyle? mapStyle; + final MinMaxZoomPreference? minMaxZoomPreference; final bool? rotateGesturesEnabled; @@ -391,6 +399,7 @@ class _AppleMapOptions { addIfNonNull('compassEnabled', compassEnabled); addIfNonNull('trafficEnabled', trafficEnabled); addIfNonNull('mapType', mapType?.index); + addIfNonNull('mapStyle', mapStyle?.index); addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?._toJson()); addIfNonNull('rotateGesturesEnabled', rotateGesturesEnabled); addIfNonNull('scrollGesturesEnabled', scrollGesturesEnabled); diff --git a/lib/src/ui.dart b/lib/src/ui.dart index d650a2a..7370a6f 100644 --- a/lib/src/ui.dart +++ b/lib/src/ui.dart @@ -16,6 +16,14 @@ enum MapType { hybrid, } +enum MapStyle { + /// Follow system style + system, + + light, + dark, +} + enum TrackingMode { // the user's location is not followed none, From 37f214a367aba8620fbaaf49c3188ffcc04bc640 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 1 Dec 2022 10:37:02 -0500 Subject: [PATCH 2/8] chore: rename property to not conflict with mapStyle --- lib/src/apple_map.dart | 14 +++++++------- lib/src/ui.dart | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/apple_map.dart b/lib/src/apple_map.dart index 0f186de..6742599 100644 --- a/lib/src/apple_map.dart +++ b/lib/src/apple_map.dart @@ -23,7 +23,7 @@ class AppleMap extends StatefulWidget { this.compassEnabled = true, this.trafficEnabled = false, this.mapType = MapType.standard, - this.mapStyle = MapStyle.system, + this.colorScheme = MapColorScheme.system, this.minMaxZoomPreference = MinMaxZoomPreference.unbounded, this.trackingMode = TrackingMode.none, this.rotateGesturesEnabled = true, @@ -59,8 +59,8 @@ class AppleMap extends StatefulWidget { /// Type of map tiles to be rendered. final MapType mapType; - /// TODO - final MapStyle mapStyle; + /// Color scheme for the standard map to use. + final MapColorScheme colorScheme; /// The mode used to track the user location. final TrackingMode trackingMode; @@ -331,7 +331,7 @@ class _AppleMapOptions { this.compassEnabled, this.trafficEnabled, this.mapType, - this.mapStyle, + this.colorScheme, this.minMaxZoomPreference, this.rotateGesturesEnabled, this.scrollGesturesEnabled, @@ -348,7 +348,7 @@ class _AppleMapOptions { compassEnabled: map.compassEnabled, trafficEnabled: map.trafficEnabled, mapType: map.mapType, - mapStyle: map.mapStyle, + colorScheme: map.colorScheme, minMaxZoomPreference: map.minMaxZoomPreference, rotateGesturesEnabled: map.rotateGesturesEnabled, scrollGesturesEnabled: map.scrollGesturesEnabled, @@ -367,7 +367,7 @@ class _AppleMapOptions { final MapType? mapType; - final MapStyle? mapStyle; + final MapColorScheme? colorScheme; final MinMaxZoomPreference? minMaxZoomPreference; @@ -399,7 +399,7 @@ class _AppleMapOptions { addIfNonNull('compassEnabled', compassEnabled); addIfNonNull('trafficEnabled', trafficEnabled); addIfNonNull('mapType', mapType?.index); - addIfNonNull('mapStyle', mapStyle?.index); + addIfNonNull('colorScheme', colorScheme?.index); addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?._toJson()); addIfNonNull('rotateGesturesEnabled', rotateGesturesEnabled); addIfNonNull('scrollGesturesEnabled', scrollGesturesEnabled); diff --git a/lib/src/ui.dart b/lib/src/ui.dart index 7370a6f..9c2235b 100644 --- a/lib/src/ui.dart +++ b/lib/src/ui.dart @@ -16,7 +16,7 @@ enum MapType { hybrid, } -enum MapStyle { +enum MapColorScheme { /// Follow system style system, From ece9ed6b4be7cb76331f0ec84315221cdba6abd9 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 1 Dec 2022 10:38:02 -0500 Subject: [PATCH 3/8] chore: remove unused variable --- ios/Classes/MapView/FlutterMapView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/ios/Classes/MapView/FlutterMapView.swift b/ios/Classes/MapView/FlutterMapView.swift index 05d41a3..603d4de 100644 --- a/ios/Classes/MapView/FlutterMapView.swift +++ b/ios/Classes/MapView/FlutterMapView.swift @@ -20,7 +20,6 @@ class FlutterMapView: MKMapView, UIGestureRecognizerDelegate { var oldBounds: CGRect? var options: Dictionary? var isMyLocationButtonShowing: Bool? = false - var mapStyle: Int? = 0 fileprivate let locationManager: CLLocationManager = CLLocationManager() From 5a8a2a35a5e528881b013a30d50279c075497344 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 1 Dec 2022 11:55:46 -0500 Subject: [PATCH 4/8] fix: rename parameter name in platform code --- ios/Classes/MapView/FlutterMapView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/Classes/MapView/FlutterMapView.swift b/ios/Classes/MapView/FlutterMapView.swift index 603d4de..171f856 100644 --- a/ios/Classes/MapView/FlutterMapView.swift +++ b/ios/Classes/MapView/FlutterMapView.swift @@ -145,10 +145,10 @@ class FlutterMapView: MKMapView, UIGestureRecognizerDelegate { self.mapType = self.mapTypes[mapType] } - if let mapStyle: Int = options["mapStyle"] as? Int { + if let colorScheme: Int = options["colorScheme"] as? Int { if #available(iOS 13.0, *) { - if mapStyle != 0 { - self.overrideUserInterfaceStyle = UIUserInterfaceStyle(rawValue: mapStyle) ?? .unspecified + if colorScheme != 0 { + self.overrideUserInterfaceStyle = UIUserInterfaceStyle(rawValue: colorScheme) ?? .unspecified } } } From 9cc222431ddc48d43bc9dba769da4eda26c24ee7 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 1 Dec 2022 12:04:20 -0500 Subject: [PATCH 5/8] fix: properly handle system setting --- ios/Classes/MapView/FlutterMapView.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ios/Classes/MapView/FlutterMapView.swift b/ios/Classes/MapView/FlutterMapView.swift index 171f856..2da1506 100644 --- a/ios/Classes/MapView/FlutterMapView.swift +++ b/ios/Classes/MapView/FlutterMapView.swift @@ -147,9 +147,7 @@ class FlutterMapView: MKMapView, UIGestureRecognizerDelegate { if let colorScheme: Int = options["colorScheme"] as? Int { if #available(iOS 13.0, *) { - if colorScheme != 0 { - self.overrideUserInterfaceStyle = UIUserInterfaceStyle(rawValue: colorScheme) ?? .unspecified - } + self.overrideUserInterfaceStyle = UIUserInterfaceStyle(rawValue: colorScheme) ?? .unspecified } } From 36e86cf48bf036fe519012f2f453626ce5771158 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 1 Dec 2022 12:05:20 -0500 Subject: [PATCH 6/8] feat: add scheme cycler to example --- example/lib/map_ui.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/example/lib/map_ui.dart b/example/lib/map_ui.dart index 35d8119..9f8b062 100644 --- a/example/lib/map_ui.dart +++ b/example/lib/map_ui.dart @@ -43,6 +43,7 @@ class MapUiBodyState extends State { bool _myLocationButtonEnabled = true; MinMaxZoomPreference _minMaxZoomPreference = MinMaxZoomPreference.unbounded; MapType _mapType = MapType.standard; + MapColorScheme _colorScheme = MapColorScheme.system; bool _rotateGesturesEnabled = true; bool _scrollGesturesEnabled = true; bool _pitchGesturesEnabled = true; @@ -98,6 +99,18 @@ class MapUiBodyState extends State { ); } + Widget _colorSchemeCycler() { + final MapColorScheme nextScheme = MapColorScheme + .values[(_colorScheme.index + 1) % MapColorScheme.values.length]; + return TextButton( + child: Text('change color scheme to $nextScheme'), + onPressed: () { + setState(() { + _colorScheme = nextScheme; + }); + }); + } + Widget _rotateToggler() { return TextButton( child: Text('${_rotateGesturesEnabled ? 'disable' : 'enable'} rotate'), @@ -170,6 +183,7 @@ class MapUiBodyState extends State { Widget build(BuildContext context) { final AppleMap appleMap = AppleMap( onMapCreated: onMapCreated, + colorScheme: _colorScheme, trackingMode: _trackingMode, initialCameraPosition: _kInitialPosition, compassEnabled: _compassEnabled, @@ -207,6 +221,7 @@ class MapUiBodyState extends State { children: [ _compassToggler(), _mapTypeCycler(), + _colorSchemeCycler(), _zoomBoundsToggler(), _rotateToggler(), _scrollToggler(), From b14b01dbe0a2d11610aefbaee68d72635716908b Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 1 Dec 2022 14:39:04 -0500 Subject: [PATCH 7/8] fix: follow theme brightness instead of platform --- lib/src/apple_map.dart | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/src/apple_map.dart b/lib/src/apple_map.dart index 6742599..3597b1f 100644 --- a/lib/src/apple_map.dart +++ b/lib/src/apple_map.dart @@ -187,7 +187,7 @@ class _AppleMapState extends State { Widget build(BuildContext context) { final Map creationParams = { 'initialCameraPosition': widget.initialCameraPosition._toMap(), - 'options': _appleMapOptions.toMap(), + 'options': _appleMapOptions.toMap(context: context), 'annotationsToAdd': _serializeAnnotationSet(widget.annotations), 'polylinesToAdd': _serializePolylineSet(widget.polylines), 'polygonsToAdd': _serializePolygonSet(widget.polygons), @@ -387,7 +387,7 @@ class _AppleMapOptions { final EdgeInsets? padding; - Map toMap() { + Map toMap({BuildContext? context}) { final Map optionsMap = {}; void addIfNonNull(String fieldName, dynamic value) { @@ -396,10 +396,22 @@ class _AppleMapOptions { } } + if (context != null) { + final systemScheme = Theme.of(context).brightness == Brightness.dark + ? MapColorScheme.dark + : MapColorScheme.light; + addIfNonNull( + 'colorScheme', + colorScheme == MapColorScheme.system + ? systemScheme.index + : colorScheme?.index); + } else { + addIfNonNull('colorScheme', colorScheme?.index); + } + addIfNonNull('compassEnabled', compassEnabled); addIfNonNull('trafficEnabled', trafficEnabled); addIfNonNull('mapType', mapType?.index); - addIfNonNull('colorScheme', colorScheme?.index); addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?._toJson()); addIfNonNull('rotateGesturesEnabled', rotateGesturesEnabled); addIfNonNull('scrollGesturesEnabled', scrollGesturesEnabled); From 108736a22cc12baaae34e702979e19b22b26dcc2 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 1 Dec 2022 15:19:35 -0500 Subject: [PATCH 8/8] Revert "fix: follow theme brightness instead of platform" This reverts commit b14b01dbe0a2d11610aefbaee68d72635716908b. --- lib/src/apple_map.dart | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/lib/src/apple_map.dart b/lib/src/apple_map.dart index 3597b1f..6742599 100644 --- a/lib/src/apple_map.dart +++ b/lib/src/apple_map.dart @@ -187,7 +187,7 @@ class _AppleMapState extends State { Widget build(BuildContext context) { final Map creationParams = { 'initialCameraPosition': widget.initialCameraPosition._toMap(), - 'options': _appleMapOptions.toMap(context: context), + 'options': _appleMapOptions.toMap(), 'annotationsToAdd': _serializeAnnotationSet(widget.annotations), 'polylinesToAdd': _serializePolylineSet(widget.polylines), 'polygonsToAdd': _serializePolygonSet(widget.polygons), @@ -387,7 +387,7 @@ class _AppleMapOptions { final EdgeInsets? padding; - Map toMap({BuildContext? context}) { + Map toMap() { final Map optionsMap = {}; void addIfNonNull(String fieldName, dynamic value) { @@ -396,22 +396,10 @@ class _AppleMapOptions { } } - if (context != null) { - final systemScheme = Theme.of(context).brightness == Brightness.dark - ? MapColorScheme.dark - : MapColorScheme.light; - addIfNonNull( - 'colorScheme', - colorScheme == MapColorScheme.system - ? systemScheme.index - : colorScheme?.index); - } else { - addIfNonNull('colorScheme', colorScheme?.index); - } - addIfNonNull('compassEnabled', compassEnabled); addIfNonNull('trafficEnabled', trafficEnabled); addIfNonNull('mapType', mapType?.index); + addIfNonNull('colorScheme', colorScheme?.index); addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?._toJson()); addIfNonNull('rotateGesturesEnabled', rotateGesturesEnabled); addIfNonNull('scrollGesturesEnabled', scrollGesturesEnabled);