I am new to flutter. my question is that how do I switch themes in the initial state of my scaffolds? I already have set up a two themes using provider and I call them on button press or set state. but I'm looking for something more convenient as in changing the theme in initial state. here is my theme code using provider
class ThemeService with ChangeNotifier {
static final ThemeData themeA =
ThemeData.light().copyWith(scaffoldBackgroundColor: Colors.black);
static final ThemeData themeB =
ThemeData.light().copyWith(scaffoldBackgroundColor: Colors.white);
ThemeData _currentTheme = themeA;
get currentTheme => _currentTheme;
switchToThemeA() {
_currentTheme = themeA;
notifyListeners();
}
switchToThemeB() {
_currentTheme = themeB;
notifyListeners();
}
}
every-time I want to change theme I call this
ThemeService themeService = Provider.of<ThemeService>(context);
themeService.switchToThemeB();
this works fine on button presses and set state but I am unable to call this in initial state. can someone help me?