Update theme_provider.dart

This commit is contained in:
Vadim 2023-02-05 00:08:05 +03:00
parent 00e104de9b
commit 24977ff852

View file

@ -44,15 +44,28 @@ class ThemeProvider extends StatefulWidget {
State<ThemeProvider> createState() => ThemeProviderState(); State<ThemeProvider> createState() => ThemeProviderState();
} }
class ThemeProviderState extends State<ThemeProvider> { class ThemeProviderState extends State<ThemeProvider> with WidgetsBindingObserver {
UserPreferencesService get _prefs => context.read<UserPreferencesService>(); UserPreferencesService get _prefs => context.read<UserPreferencesService>();
late final _themeTypeNotifier = ValueNotifier<ThemeType>(_prefs.themeType); late final _themeTypeNotifier = ValueNotifier<ThemeType>(_prefs.themeType);
late final _dynamicColorNotifier = ValueNotifier<bool>(_prefs.dynamicColor); late final _dynamicColorNotifier = ValueNotifier<bool>(_prefs.dynamicColor);
late final _primaryColorNotifier = ValueNotifier<Color>(_prefs.primaryColor); late final _primaryColorNotifier = ValueNotifier<Color>(_prefs.primaryColor);
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangePlatformBrightness() {
super.didChangePlatformBrightness();
setState(() {});
}
@override @override
void dispose() { void dispose() {
WidgetsBinding.instance.removeObserver(this);
_themeTypeNotifier.dispose(); _themeTypeNotifier.dispose();
_dynamicColorNotifier.dispose(); _dynamicColorNotifier.dispose();
_primaryColorNotifier.dispose(); _primaryColorNotifier.dispose();