setThemeData method

Color? setThemeData({
  1. ColorSwatch<int?>? swatch,
})

Set the app's general color theme supplying a Color value.

Implementation

Color? setThemeData({
  ColorSwatch<int?>? swatch,
}) {
  //
  final value = swatch?.toARGB32();

  /// if (!Prefs.ready()) {
  ///   return value == null ? null : Color(value);
  /// }

  MaterialColor? materialColor;
  Color? color;
  int index = -1;

  if (value != null) {
    color = Color(value);
    materialColor = swatch as MaterialColor;
    index =
        Colors.primaries.indexOf(materialColor); // Returns -1 if not found.
    ///      Prefs.setInt('primaryIndex', index);
  } else {
    ///     index = Prefs.getInt('primaryIndex', -1);
  }

  if (index > -1) {
    //
    materialColor = Colors.primaries[index];

    color ??= Color(materialColor.toARGB32());

    /// Assign the colour to the floating button as well.
    themeData = ThemeData(
      useMaterial3: false,
      primarySwatch: materialColor,
      floatingActionButtonTheme: FloatingActionButtonThemeData(
        backgroundColor: color,
      ),
    );
  }
  return color;
}