Color conversion utilities: hex <-> RGB <-> ARGB, palette helpers.
Uses plain Dart int to represent colors (0xAARRGGBB), so it works in
pure Dart projects without Flutter dependency.
Example:
ColorUtil.hexToInt('#FF5733'); // 0xFFFF5733
ColorUtil.intToRgb(0xFFFF5733); // [255, 87, 51]
ColorUtil.rgbToInt(255, 87, 51); // 0xFFFF5733
ColorUtil.intToHex(0xFFFF5733); // #FF5733
ColorUtil.isDark(0xFF000000); // true
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
alpha(
int color) → int -
Alpha channel
0, 255. -
argb(
int color) → List< int> -
Returns
[a, r, g, b]each in0, 255. -
argbToInt(
int a, int r, int g, int b) → int -
Build ARGB int from channels (all
0, 255). -
blue(
int color) → int -
Blue channel
0, 255. -
fromHex(
String hex, {int fallback = 0xFF000000}) → int -
Same as tryParse but returns
fallbackinstead of -1 on failure. -
green(
int color) → int -
Green channel
0, 255. -
invert(
int color) → int - Invert the RGB channels (alpha preserved).
-
isDark(
int color) → bool - Whether the color is "dark" (luminance < 0.5).
-
isLight(
int color) → bool - Whether the color is "light" (luminance >= 0.5).
-
lerp(
int a, int b, double t) → int -
Linearly interpolate between
aandbby factort(0..1). -
luminance(
int color) → double -
Relative luminance (per WCAG formula). Range
0, 1. -
red(
int color) → int -
Red channel
0, 255. -
rgb(
int color) → List< int> -
Returns
[r, g, b](no alpha). -
rgbToInt(
int r, int g, int b) → int - Build RGB int with full opacity alpha.
-
toHex(
int color) → String -
Convert color int to
#RRGGBBformat (alpha stripped). -
toHexArgb(
int color) → String -
Convert color int to
#AARRGGBBformat. -
tryParse(
String hex) → int -
Parse a hex color string to int. Accepts
#RGB,#RRGGBB,#AARRGGBBand plainRRGGBB/AARRGGBBwithout leading#. Returns -1 if invalid. -
withAlpha(
int color, int a) → int -
Returns a copy of
colorwith alpha overridden. -
withBlue(
int color, int b) → int -
Returns a copy of
colorwith blue overridden. -
withGreen(
int color, int g) → int -
Returns a copy of
colorwith green overridden. -
withRed(
int color, int r) → int -
Returns a copy of
colorwith red overridden.