setIsDark method
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);
}
}