setTheme method

Future setTheme(
  1. ThemeMode themeMode
)

Change the theme of the app (dark/light) depending on a boolean toggle value. Notify listeners (main Material App) when called, to rebuild the entire widget tree.

themeMode: ThemeMode value, usually provided by a toggle. If equals ThemeMode.light, set light theme, otherwise set dark theme.

Implementation

Future setTheme(ThemeMode themeMode) async {
  this.themeMode = themeMode;
  await _saveThemePreference(mode: themeMode);
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarBrightness:
          themeMode == ThemeMode.light ? Brightness.light : Brightness.dark));
  notifyListeners();
}