From b8c6f51bd01bce892ab44624906ab15cdbef23de Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Sun, 5 Feb 2023 00:09:19 +0300 Subject: [PATCH] ML-10 `ThemeType.systemDefault` doesn't reflect theme change from device settings (#22) --- lib/providers/theme_provider.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/providers/theme_provider.dart b/lib/providers/theme_provider.dart index c8cf228..840d4fa 100644 --- a/lib/providers/theme_provider.dart +++ b/lib/providers/theme_provider.dart @@ -44,15 +44,28 @@ class ThemeProvider extends StatefulWidget { State createState() => ThemeProviderState(); } -class ThemeProviderState extends State { +class ThemeProviderState extends State with WidgetsBindingObserver { UserPreferencesService get _prefs => context.read(); late final _themeTypeNotifier = ValueNotifier(_prefs.themeType); late final _dynamicColorNotifier = ValueNotifier(_prefs.dynamicColor); late final _primaryColorNotifier = ValueNotifier(_prefs.primaryColor); + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addObserver(this); + } + + @override + void didChangePlatformBrightness() { + super.didChangePlatformBrightness(); + setState(() {}); + } + @override void dispose() { + WidgetsBinding.instance.removeObserver(this); _themeTypeNotifier.dispose(); _dynamicColorNotifier.dispose(); _primaryColorNotifier.dispose();