FlexColorExtensions 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. 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 FlexColorScheme, 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 FlexColorScheme'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.
The color extension also include getting a color's RGB hex code as a string in two different formats. Extension hexCode returns a Flutter style HEX code string of a Color value, meaning it starts with 0x and alpha value before the RGB Hex values. The plain hex extension returns a typical API formatted hex color string starting with # and no alpha value.
- on
Properties
- hex → String
-
Return uppercase RGB hex code string, with # and no alpha value.
This format is often used in APIs and in CSS color values..
no setter
- 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
- onColor → Color
-
Get the right black or white contrasting onColor for a color.
no setter
Methods
-
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%.
-
darken(
[int amount = 10]) → Color - Darkens the color with the given integer percentage amount. Defaults to 10%.
-
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%.