Skip to content

Commit 13eb3e4

Browse files
juaoosefreekvandeven
authored andcommitted
fix: follow theme brightness instead of platform
1 parent 62430d2 commit 13eb3e4

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.4.0
4+
5+
* Add option to set a `colorScheme` for the map (system, light, dark)
6+
37
## 1.3.0
48

59
* Animate marker position changes instead of removing and re-adding

lib/src/apple_map.dart

+15-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class _AppleMapState extends State<AppleMap> {
192192
Widget build(BuildContext context) {
193193
final Map<String, dynamic> creationParams = <String, dynamic>{
194194
'initialCameraPosition': widget.initialCameraPosition._toMap(),
195-
'options': _appleMapOptions.toMap(),
195+
'options': _appleMapOptions.toMap(context: context),
196196
'annotationsToAdd': _serializeAnnotationSet(widget.annotations),
197197
'polylinesToAdd': _serializePolylineSet(widget.polylines),
198198
'polygonsToAdd': _serializePolygonSet(widget.polygons),
@@ -396,7 +396,7 @@ class _AppleMapOptions {
396396

397397
final bool? insetsLayoutMarginsFromSafeArea;
398398

399-
Map<String, dynamic> toMap() {
399+
Map<String, dynamic> toMap({BuildContext? context}) {
400400
final Map<String, dynamic> optionsMap = <String, dynamic>{};
401401

402402
void addIfNonNull(String fieldName, dynamic value) {
@@ -405,10 +405,22 @@ class _AppleMapOptions {
405405
}
406406
}
407407

408+
if (context != null) {
409+
final systemScheme = Theme.of(context).brightness == Brightness.dark
410+
? MapColorScheme.dark
411+
: MapColorScheme.light;
412+
addIfNonNull(
413+
'colorScheme',
414+
colorScheme == MapColorScheme.system
415+
? systemScheme.index
416+
: colorScheme?.index);
417+
} else {
418+
addIfNonNull('colorScheme', colorScheme?.index);
419+
}
420+
408421
addIfNonNull('compassEnabled', compassEnabled);
409422
addIfNonNull('trafficEnabled', trafficEnabled);
410423
addIfNonNull('mapType', mapType?.index);
411-
addIfNonNull('colorScheme', colorScheme?.index);
412424
addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?._toJson());
413425
addIfNonNull('rotateGesturesEnabled', rotateGesturesEnabled);
414426
addIfNonNull('scrollGesturesEnabled', scrollGesturesEnabled);

lib/src/ui.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ enum MapType {
1919
enum MapColorScheme {
2020
/// Follow system style
2121
system,
22-
23-
light,
22+
23+
light,
2424
dark,
2525
}
2626

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: apple_maps_flutter
22
description: This plugin uses the Flutter platform view to display an Apple Maps widget.
3-
version: 1.3.0
3+
version: 1.4.0
44
homepage: https://luisthein.de
55
repository: https://github.com/LuisThein/apple_maps_flutter
66
issue_tracker: https://github.com/LuisThein/apple_maps_flutter/issues

0 commit comments

Comments
 (0)