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(), diff --git a/ios/Classes/MapView/FlutterMapView.swift b/ios/Classes/MapView/FlutterMapView.swift index 628d533..2da1506 100644 --- a/ios/Classes/MapView/FlutterMapView.swift +++ b/ios/Classes/MapView/FlutterMapView.swift @@ -144,6 +144,12 @@ class FlutterMapView: MKMapView, UIGestureRecognizerDelegate { if let mapType: Int = options["mapType"] as? Int { self.mapType = self.mapTypes[mapType] } + + if let colorScheme: Int = options["colorScheme"] as? Int { + if #available(iOS 13.0, *) { + self.overrideUserInterfaceStyle = UIUserInterfaceStyle(rawValue: colorScheme) ?? .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..6742599 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.colorScheme = MapColorScheme.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; + /// Color scheme for the standard map to use. + final MapColorScheme colorScheme; + /// The mode used to track the user location. final TrackingMode trackingMode; @@ -327,6 +331,7 @@ class _AppleMapOptions { this.compassEnabled, this.trafficEnabled, this.mapType, + this.colorScheme, this.minMaxZoomPreference, this.rotateGesturesEnabled, this.scrollGesturesEnabled, @@ -343,6 +348,7 @@ class _AppleMapOptions { compassEnabled: map.compassEnabled, trafficEnabled: map.trafficEnabled, mapType: map.mapType, + colorScheme: map.colorScheme, minMaxZoomPreference: map.minMaxZoomPreference, rotateGesturesEnabled: map.rotateGesturesEnabled, scrollGesturesEnabled: map.scrollGesturesEnabled, @@ -361,6 +367,8 @@ class _AppleMapOptions { final MapType? mapType; + final MapColorScheme? colorScheme; + final MinMaxZoomPreference? minMaxZoomPreference; final bool? rotateGesturesEnabled; @@ -391,6 +399,7 @@ class _AppleMapOptions { 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 d650a2a..9c2235b 100644 --- a/lib/src/ui.dart +++ b/lib/src/ui.dart @@ -16,6 +16,14 @@ enum MapType { hybrid, } +enum MapColorScheme { + /// Follow system style + system, + + light, + dark, +} + enum TrackingMode { // the user's location is not followed none,