Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add colorScheme parameter #42

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions example/lib/map_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MapUiBodyState extends State<MapUiBody> {
bool _myLocationButtonEnabled = true;
MinMaxZoomPreference _minMaxZoomPreference = MinMaxZoomPreference.unbounded;
MapType _mapType = MapType.standard;
MapColorScheme _colorScheme = MapColorScheme.system;
bool _rotateGesturesEnabled = true;
bool _scrollGesturesEnabled = true;
bool _pitchGesturesEnabled = true;
Expand Down Expand Up @@ -98,6 +99,18 @@ class MapUiBodyState extends State<MapUiBody> {
);
}

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'),
Expand Down Expand Up @@ -170,6 +183,7 @@ class MapUiBodyState extends State<MapUiBody> {
Widget build(BuildContext context) {
final AppleMap appleMap = AppleMap(
onMapCreated: onMapCreated,
colorScheme: _colorScheme,
trackingMode: _trackingMode,
initialCameraPosition: _kInitialPosition,
compassEnabled: _compassEnabled,
Expand Down Expand Up @@ -207,6 +221,7 @@ class MapUiBodyState extends State<MapUiBody> {
children: <Widget>[
_compassToggler(),
_mapTypeCycler(),
_colorSchemeCycler(),
_zoomBoundsToggler(),
_rotateToggler(),
_scrollToggler(),
Expand Down
6 changes: 6 additions & 0 deletions ios/Classes/MapView/FlutterMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, *) {
Expand Down
9 changes: 9 additions & 0 deletions lib/src/apple_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -327,6 +331,7 @@ class _AppleMapOptions {
this.compassEnabled,
this.trafficEnabled,
this.mapType,
this.colorScheme,
this.minMaxZoomPreference,
this.rotateGesturesEnabled,
this.scrollGesturesEnabled,
Expand All @@ -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,
Expand All @@ -361,6 +367,8 @@ class _AppleMapOptions {

final MapType? mapType;

final MapColorScheme? colorScheme;

final MinMaxZoomPreference? minMaxZoomPreference;

final bool? rotateGesturesEnabled;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions lib/src/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down