setIsDark method

Future<void> setIsDark({
  1. required bool isDark,
  2. required bool shouldSave,
})

Sets the dark mode. If shouldSave is true, it will save it in shared preferences.

This triggers a rebuild of the widgets utilizing the DynamicColorTheme.

Implementation

Future<void> setIsDark({
  required bool isDark,
  required bool shouldSave,
}) async {
  setState(() {
    _data = widget.data(_color, isDark);
    _isDark = isDark;
  });

  if (shouldSave) {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setBool(_isDarkSharedPreferencesKey, isDark);
  }
}