setColor method

Future<void> setColor({
  1. required Color color,
  2. required bool shouldSave,
})

Sets the provided color. If shouldSave is true, it will save it in shared preferences.

This triggers a rebuild of the widgets utilizing the DynamicColorTheme.

Implementation

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

  if (shouldSave) {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setInt(_colorSharedPreferencesKey, color.value);
  }
}