I am using of provider to change theme in my app. My app initialize first with dark theme.
class ThemeNotifier extends ChangeNotifier {
final String key = "them";
SharedPreferences _prefs;
bool _darkTheme;
bool get darkTheme => _darkTheme;
ThemeNotifier() {
_darkTheme = true;
_loadFromPrefs();
}
toggleTheme() {
_darkTheme = !_darkTheme;
_saveToPrefs();
notifyListeners();
}
_loadFromPrefs() async {
await _initPrefs();
_darkTheme = _prefs.getBool(key) ?? true;
notifyListeners();
}
_saveToPrefs() async {
await _initPrefs();
_prefs.setBool(key, _darkTheme);
}
_initPrefs() async {
if (_prefs == null) _prefs = await SharedPreferences.getInstance();
}
}
When i changed them to light i call toggleTheme
method and i change _darkTheme to false.
I use above codes like this:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider.value(
value: ThemeNotifier(),
child: Consumer<ThemeNotifier>(
builder: (context, notifire, child) {
child:
return MaterialApp(
title: "theme",
theme: notifire.darkTheme ? dark : light,
home: HomeScreen(),
);
},
),
);
}
}
but when i change app with light theme and do hot reload application for just a second my app theme is dark and then changed into light mode.
How could i load application without dark mode when i use light mode?that is mean when i change them to light mode i do not want to show dark mode even for a few millisecond ?