Skip to content

Commit 0e4dd68

Browse files
authored
Fix system brightness setting (#212)
* Use correct brightness when enabling system brightness * Listen to system brightness changes if needed * Use final instead of var
1 parent 3d250f4 commit 0e4dd68

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/main.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,24 @@ class _AppState extends State<App> {
5656
//TODO: wait until settings is ready?
5757
settings.onChange().listen((_) {
5858
setState(() {
59-
if (!settings.useSystemColors) {
59+
if (settings.useSystemColors) {
60+
brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness;
61+
} else {
6062
brightness = settings.darkMode ? Brightness.dark : Brightness.light;
6163
}
6264
});
6365
});
6466

67+
// Listen to changes to the system brightness mode, update accordingly
68+
final dispatcher = SchedulerBinding.instance.platformDispatcher;
69+
dispatcher.onPlatformBrightnessChanged = () {
70+
if (settings.useSystemColors) {
71+
setState(() {
72+
brightness = dispatcher.platformBrightness;
73+
});
74+
}
75+
};
76+
6577
super.initState();
6678
}
6779

0 commit comments

Comments
 (0)