ZetaColorExtensions extension

Extensions on Color to brighten, lighten, darken and blend colors and can get a shade for gradients.

Some of the extensions are rewrites of TinyColor's functions https://pub.dev/packages/tinycolor. See LICENSE-3RD-PARTY.

The TinyColor algorithms have also been modified to use Flutter's HSLColor class instead of the custom one in the TinyColor lib. The functions from TinyColor re-implemented as Color extensions here are brighten, lighten and darken. They are used for color calculations in ZetaColorScheme, but also exposed for reuse.

Another frequently used extension is blend and blendAlpha used to blend two colors using alpha as a percentage or as an 8-bit int alpha value. This extension is used to calculate branded surface colors used by ZetaColorScheme's branded surfaces and for automatic dark color schemes from a light scheme.

The getShadeColor extension is less frequently used and when used, typically used to color makes colors shades for gradient AppBars, with default setting to not change black and white.

on

Properties

hexCode String
Return uppercase Flutter style hex code string of the color.
no setter
isDark bool
Returns true if the color's brightness is Brightness.dark, else false.
no setter
isLight bool
Returns true if the color's brightness is Brightness.light, else false.
no setter
lightness double
Gets lightness of color.
no setter
onColor Color
This getter returns appropriate contrast color based on a given color. It will return a color chosen according to the brightness of this color.
no setter
zetaColorSwatch ZetaColorSwatch
ZetaColorSwatch is a color swatch utility to produce different shades of a primary color, following a specific progression of lightness and darkness.
no setter

Methods

adjustContrast({required Color on, required double target, int maxIterations = 1000, double epsilon = 0.1}) Color
Adjusts the color to a specific contrast target.
blend(Color input, [int amount = 10]) Color
Blend in the given input Color with a percentage of alpha.
blendAlpha(Color input, [int alpha = 0x0A]) Color
Blend in the given input Color with an alpha value.
brighten([int amount = 10]) Color
Brightens the color with the given integer percentage amount. Defaults to 10%.
contrastRatio(Color b) double
Calculates the contrast ratio between the current color and the given color b.
darken([int amount = 10]) Color
Darkens the color with the given integer percentage amount. Defaults to 10%.
ensureAccessibility({required Color on, ZetaContrast standard = ZetaContrast.aa}) Color
Adjusts the current color to meet the specified accessibility standard standard when set against the on color.
generateSwatch({int primary = kZetaSwatchPrimaryIndex, Map<int, double> targetContrasts = kZetaSwatchTargetContrasts, Color background = ZetaColorBase.white, bool adjustPrimary = true}) Map<int, Color>
Generates a color swatch for this color. A color swatch is a map with integer keys indexing to Color objects, typically used for design themes.
getShadeColor({int shadeValue = 15, bool lighten = true, bool keepBlack = true, bool keepWhite = true}) Color
The getShadeColor extension is used to make a color darker or lighter, the shadeValue defines the amount in % that the shade should be changed.
lighten([int amount = 10]) Color
Lightens the color with the given integer percentage amount. Defaults to 10%.
withLightness(double percentage) Color
Applies lightness percentage to color.