setThemeData static method

ColorSwatch<int?>? setThemeData([
  1. ColorSwatch<int?>? value
])

Set the App's general color theme supplying a ColorSwatch value.

Implementation

static ColorSwatch<int?>? setThemeData([ColorSwatch<int?>? value]) {
  //
  if (!Prefs.ready()) {
    return value;
  }

  if (value != null) {
    Prefs.setInt(
      'colorTheme',
      Colors.primaries.indexOf(value as MaterialColor),
    );
  } else {
    final swatch = Prefs.getInt('colorTheme', -1);
    // If never set in the first place, ignore
    if (swatch > -1) {
      value = Colors.primaries[swatch];
    }
  }

  if (value != null) {
    /// Assign the colour to the floating button as well.
    themeData = ThemeData(
      primarySwatch: value as MaterialColor,
      floatingActionButtonTheme: FloatingActionButtonThemeData(
        backgroundColor: value,
      ),
    );
    iOSTheme = value;
  }
  return value;
}