Skip to content

Commit

Permalink
fix: follow theme brightness instead of platform
Browse files Browse the repository at this point in the history
  • Loading branch information
juaoose authored and freekvandeven committed Nov 13, 2024
1 parent 62430d2 commit 13eb3e4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.0

* Add option to set a `colorScheme` for the map (system, light, dark)

## 1.3.0

* Animate marker position changes instead of removing and re-adding
Expand Down
18 changes: 15 additions & 3 deletions lib/src/apple_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class _AppleMapState extends State<AppleMap> {
Widget build(BuildContext context) {
final Map<String, dynamic> creationParams = <String, dynamic>{
'initialCameraPosition': widget.initialCameraPosition._toMap(),
'options': _appleMapOptions.toMap(),
'options': _appleMapOptions.toMap(context: context),
'annotationsToAdd': _serializeAnnotationSet(widget.annotations),
'polylinesToAdd': _serializePolylineSet(widget.polylines),
'polygonsToAdd': _serializePolygonSet(widget.polygons),
Expand Down Expand Up @@ -396,7 +396,7 @@ class _AppleMapOptions {

final bool? insetsLayoutMarginsFromSafeArea;

Map<String, dynamic> toMap() {
Map<String, dynamic> toMap({BuildContext? context}) {
final Map<String, dynamic> optionsMap = <String, dynamic>{};

void addIfNonNull(String fieldName, dynamic value) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ enum MapType {
enum MapColorScheme {
/// Follow system style
system,
light,

light,
dark,
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: apple_maps_flutter
description: This plugin uses the Flutter platform view to display an Apple Maps widget.
version: 1.3.0
version: 1.4.0
homepage: https://luisthein.de
repository: https://github.com/LuisThein/apple_maps_flutter
issue_tracker: https://github.com/LuisThein/apple_maps_flutter/issues
Expand Down

0 comments on commit 13eb3e4

Please sign in to comment.