Fix system brightness setting (#212)

* Use correct brightness when enabling system brightness

* Listen to system brightness changes if needed

* Use final instead of var
This commit is contained in:
Ian VanSchooten 2024-12-20 15:18:07 -05:00 committed by GitHub
parent 3d250f4e41
commit 0e4dd68b84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 1 deletions

View File

@ -56,12 +56,24 @@ class _AppState extends State<App> {
//TODO: wait until settings is ready? //TODO: wait until settings is ready?
settings.onChange().listen((_) { settings.onChange().listen((_) {
setState(() { setState(() {
if (!settings.useSystemColors) { if (settings.useSystemColors) {
brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness;
} else {
brightness = settings.darkMode ? Brightness.dark : Brightness.light; brightness = settings.darkMode ? Brightness.dark : Brightness.light;
} }
}); });
}); });
// Listen to changes to the system brightness mode, update accordingly
final dispatcher = SchedulerBinding.instance.platformDispatcher;
dispatcher.onPlatformBrightnessChanged = () {
if (settings.useSystemColors) {
setState(() {
brightness = dispatcher.platformBrightness;
});
}
};
super.initState(); super.initState();
} }