ZetaColorSwatch.fromColor constructor

ZetaColorSwatch.fromColor(
  1. Color primary, {
  2. Color background = Colors.white,
})

ZetaColorSwatch is a color swatch utility to produce different shades of a primary color, following a specific progression of lightness and darkness.

This factory constructor creates a color swatch based on a provided primary color. The darker and lighter shades are determined by predefined percentage values.

It ensures that the 60th and 80th shades from swatch abide by AA and AAA accessibility standards on background, respectively.

Implementation

// TODO(UX-1144): Find a way to make this better
factory ZetaColorSwatch.fromColor(
  Color primary, {
  Color background = Colors.white,
}) {
  /// Returns a map of colors shades with their respective indexes.
  /// Darker shades are obtained by darkening the primary color and
  /// lighter shades by lightening it.
  ///
  /// - 100, 90, 80, and 70 are darker shades of the primary color.
  /// - 60 is the primary color itself.
  /// - 50, 40, 30, 20, and 10 are progressively lighter shades of the primary color.
  if (primary is ZetaColorSwatch) {
    return primary;
  } else if (primary is MaterialColor) {
    return ZetaColorSwatch.fromMaterialColor(primary);
  }
  return ZetaColorSwatch(
    primary: primary.intValue,
    swatch: primary.generateSwatch(background: background),
  );
}