ZetaColorSwatch.fromColor constructor
- Color primary, {
- Brightness brightness = Brightness.light,
- ZetaContrast contrast = ZetaContrast.aa,
- 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 are abide by the AA and AAA accessibility standards on background
, respectively.
background
color defaults to ZetaColorBase.warm shade10.
Implementation
factory ZetaColorSwatch.fromColor(
Color primary, {
Brightness brightness = Brightness.light,
ZetaContrast contrast = ZetaContrast.aa,
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.
return ZetaColorSwatch(
contrast: contrast,
brightness: brightness,
primary: primary.value,
swatch: primary.generateSwatch(background: background),
).apply(brightness: brightness);
}