From ed93fb059753975689a528535e207519c1efecbd 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 1e733ed..35f1c00 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 793a269..6b679fe 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, @@ -59,6 +60,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; @@ -332,6 +336,7 @@ class _AppleMapOptions { this.compassEnabled, this.trafficEnabled, this.mapType, + this.mapStyle, this.minMaxZoomPreference, this.rotateGesturesEnabled, this.scrollGesturesEnabled, @@ -349,6 +354,7 @@ class _AppleMapOptions { compassEnabled: map.compassEnabled, trafficEnabled: map.trafficEnabled, mapType: map.mapType, + mapStyle: map.mapStyle, minMaxZoomPreference: map.minMaxZoomPreference, rotateGesturesEnabled: map.rotateGesturesEnabled, scrollGesturesEnabled: map.scrollGesturesEnabled, @@ -368,6 +374,8 @@ class _AppleMapOptions { final MapType? mapType; + final MapStyle? mapStyle; + final MinMaxZoomPreference? minMaxZoomPreference; final bool? rotateGesturesEnabled; @@ -400,6 +408,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 71c00a5..02bb5ca 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 1ff4b357cc865d53a42464d1794fc110617b4b4b 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 6b679fe..a4dcce6 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, @@ -60,8 +60,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; @@ -336,7 +336,7 @@ class _AppleMapOptions { this.compassEnabled, this.trafficEnabled, this.mapType, - this.mapStyle, + this.colorScheme, this.minMaxZoomPreference, this.rotateGesturesEnabled, this.scrollGesturesEnabled, @@ -354,7 +354,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, @@ -374,7 +374,7 @@ class _AppleMapOptions { final MapType? mapType; - final MapStyle? mapStyle; + final MapColorScheme? colorScheme; final MinMaxZoomPreference? minMaxZoomPreference; @@ -408,7 +408,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 02bb5ca..f9bdfc5 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 1fe4f36c71afbcc5a51d3ec409fae5f2f7f408e5 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 35f1c00..24524a6 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 53a424892f9ed263119ed9cfa7b81886a49d6d3d 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 24524a6..21c9a17 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 4d22b96bb00cb692b4d9709c488c94209f735f64 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 21c9a17..19c468b 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 b24cd02b0881c0390f228227ab3819ee2f88cf5e 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 23871715b04efe747bde9f43386305bbdb1beda6 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 --- CHANGELOG.md | 4 ++++ lib/src/apple_map.dart | 18 +++++++++++++++--- lib/src/ui.dart | 4 ++-- pubspec.yaml | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f793020..830233b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.5.0 + +* Add option to set a `colorScheme` for the map (system, light, dark) + ## 1.4.0 * Flutter 3.27.1 compatibility, replace `ui.hash*` with `Object.hash* diff --git a/lib/src/apple_map.dart b/lib/src/apple_map.dart index a4dcce6..a94bd6c 100644 --- a/lib/src/apple_map.dart +++ b/lib/src/apple_map.dart @@ -192,7 +192,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), @@ -396,7 +396,7 @@ class _AppleMapOptions { final bool? insetsLayoutMarginsFromSafeArea; - Map toMap() { + Map toMap({BuildContext? context}) { final Map optionsMap = {}; void addIfNonNull(String fieldName, dynamic value) { @@ -405,10 +405,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); diff --git a/lib/src/ui.dart b/lib/src/ui.dart index f9bdfc5..b32e119 100644 --- a/lib/src/ui.dart +++ b/lib/src/ui.dart @@ -19,8 +19,8 @@ enum MapType { enum MapColorScheme { /// Follow system style system, - - light, + + light, dark, } diff --git a/pubspec.yaml b/pubspec.yaml index 8fb876c..d351508 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: apple_maps_flutter description: This plugin uses the Flutter platform view to display an Apple Maps widget. -version: 1.4.0 +version: 1.5.0 homepage: https://luisthein.de repository: https://github.com/LuisThein/apple_maps_flutter issue_tracker: https://github.com/LuisThein/apple_maps_flutter/issues From 45120b16b2518fce82b4f512464d5a6ff9d238ba Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Tue, 1 Apr 2025 08:39:42 +0200 Subject: [PATCH 8/8] chore: add .vscode to .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b80c8d4..367f6f6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ # The .vscode folder contains launch configuration and tasks you configure in # VS Code which you may wish to be included in version control, so this line # is commented out by default. -#.vscode/ +.vscode/ # Flutter/Dart/Pub related **/doc/api/