ML-10 ThemeType.systemDefault doesn't reflect theme change from device settings (#22)

This commit is contained in:
Vadim 2023-02-05 00:09:19 +03:00 committed by GitHub
parent 00e104de9b
commit b8c6f51bd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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();