From 0e4dd68b8457a736e76c8ce66b5159e79a6fe6b8 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Fri, 20 Dec 2024 15:18:07 -0500 Subject: [PATCH] Fix system brightness setting (#212) * Use correct brightness when enabling system brightness * Listen to system brightness changes if needed * Use final instead of var --- lib/main.dart | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index adeaf3d..a81f1a6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -56,12 +56,24 @@ class _AppState extends State { //TODO: wait until settings is ready? settings.onChange().listen((_) { setState(() { - if (!settings.useSystemColors) { + if (settings.useSystemColors) { + brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness; + } else { 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(); }