setThemeData static method
Set the App's general color theme supplying a Color value.
Implementation
static Color? setThemeData({
ColorSwatch<int?>? swatch,
Color? color,
}) {
//
int? value = color?.value ?? swatch?.value;
if (!Prefs.ready()) {
return value == null ? null : Color(value);
}
if (value != null) {
Prefs.setInt('primaryColor', value);
color = Color(value);
} else {
value = Prefs.getInt('primaryColor', -1);
// If never set in the first place, ignore
if (value > -1) {
color = Color(value);
} else {
color = Colors.blue;
Prefs.setInt('primaryColor', color.value);
}
}
MaterialColor? materialColor;
if (swatch == null) {
materialColor = _materialColor(color);
} else {
materialColor = swatch as MaterialColor;
}
final index = Colors.primaries.indexOf(materialColor!);
if (index > -1) {
materialColor = Colors.primaries[index];
}
/// Assign the colour to the floating button as well.
themeData = ThemeData(
primarySwatch: materialColor,
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: color,
),
);
iOSTheme = color;
return color;
}