Colour class

A rich colour class that implements Flutter's Color interface while adding multi-format input/output and colour space conversions.

Colour stores colour as ARGB integer components (0-255 each) and can be created from hex strings, RGB/ARGB values, HSV/HSL values, percentages, fractions, base-256 strings, or existing Color objects.

Constructors

Constructor Input Format
Colour() Raw ARGB integers (0-255)
Colour.fromRGB() RGB integers with full opacity
Colour.fromARGB() RGB integers with opacity as percentage
Colour.fromHex() Hex string (#FF0000, #F00, FF0000)
Colour.fromHSV() Hue (0-360), Saturation, Value (0-1)
Colour.fromHSL() Hue (0-360), Saturation, Lightness (0-1)
Colour.fromPercent() ARGB as percentages (0-100)
Colour.fromFraction() ARGB as fractions (0.0-1.0)
Colour.fromB256() 4-character base-256 encoded string
Colour.fromColor() Existing Flutter Color

Output Formats

Getter Example Output
hex 'FFFF0000'
rgb '255,0,0'
argb '255,255,0,0'
b256 Base-256 string
Inheritance
Implemented types
Available extensions

Constructors

Colour({int alpha = 255, int red = 255, int green = 255, int blue = 255})
const
Colour.fromARGB({double opacity = 100, int red = 255, int green = 255, int blue = 255})
factory
Colour.fromB256(String data)
Colour.fromColor(Color color)
Colour.fromFraction({double alpha = 1.0, double red = 1.0, double green = 1.0, double blue = 1.0})
Colour.fromHex({required String hexString})
factory
Colour.fromHSL({required double h, required double s, required double l})
factory
Colour.fromHSLColour(HSLColour hslColour)
factory
Colour.fromHSV({double a = 1.0, required double h, required double s, required double v})
factory
Colour.fromHSVColour(HSVColour hsvColour)
factory
Colour.fromPercent({double a = 100, double r = 100, double g = 100, double b = 100})
Colour.fromRGB({required int red, required int green, required int blue})
const

Properties

a double
The alpha channel of this color.
no setteroverride
alpha int
The alpha (opacity) channel, 0-255.
final
argb String
Comma-separated ARGB string (e.g. '255,255,0,0').
no setter
b double
The blue channel of this color.
no setteroverride
b256 String
The ARGB value as a 4-character base-256 encoded string.
no setter
blue int
The blue channel, 0-255.
final
color Color
Returns this Colour as a standard Flutter Color.
no setter
colorSpace ColorSpace
The color space of this color.
no setteroverride
colour Colour

Available on Color, provided by the c extension

Converts this Color to a Colour instance.
no setter
g double
The green channel of this color.
no setteroverride
green int
The green channel, 0-255.
final
hashCode int
The hash code for this object.
no setteroverride
hex String
The ARGB value as an 8-character hex string (e.g. 'FFFF0000').
no setter
hsl HSLColour
This colour converted to the HSL colour space.
no setter
hsv HSVColour
This colour converted to the HSV colour space.
no setter
hsvValue double
no setter
hue double
no setter
lightness double
no setter
opacity double
The alpha channel of this color as a double.
no setteroverride
r double
The red channel of this color.
no setteroverride
red int
The red channel, 0-255.
final
rgb String
Comma-separated RGB string (e.g. '255,0,0').
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
saturation double
no setter
value int
A 32 bit value representing this color.
no setteroverride

Methods

computeLuminance() double
Returns a brightness value between 0 for darkest and 1 for lightest.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
print() String
toARGB32() int
Returns a 32-bit value representing this color.
override
toColour() Colour
Converts this colour to its Colour (ARGB) representation.
override
toHSL() HSLColour
Converts this colour to its HSLColour representation.
override
toHSLColor() HSLColor
toHSV() HSVColour
Converts this colour to its HSVColour representation.
override
toHSVColor() HSVColor
toString() String
A string representation of this object.
override
withAlpha(int alpha) Colour
Returns a new color that matches this color with the alpha channel replaced with a (which ranges from 0 to 255).
override
withBlue(int blue) Colour
Returns a new color that matches this color with the blue channel replaced with b (which ranges from 0 to 255).
override
withGreen(int green) Colour
Returns a new color that matches this color with the green channel replaced with g (which ranges from 0 to 255).
override
withHsvValue(double value) Colour
withHue(double hue) Colour
withLightness(double lightness) Colour
withOpacity(double opacity) Colour
Returns a new color that matches this color with the alpha channel replaced with the given opacity (which ranges from 0.0 to 1.0).
override
withRed(int red) Colour
Returns a new color that matches this color with the red channel replaced with r (which ranges from 0 to 255).
override
withSaturation(double saturation) Colour
withValues({double? alpha, double? red, double? green, double? blue, ColorSpace? colorSpace}) Colour
Returns a new color with the provided components updated.
override

Operators

operator ==(Object other) bool
The equality operator.
override