Colour class

An RGB colour with 8-bit channels that can be used anywhere a Flutter Color is expected.

Stores alpha, red, green and blue as whole numbers from 0 to 255, and adds constructors for hex, percentages, fractions, HSV and HSL, plus getters for common text formats.

const orange = Colour.fromRGB(red: 255, green: 152, blue: 0);
orange.hex;  // 'FFFF9800'
orange.rgb;  // '255,152,0'
Inheritance
Implemented types
Available extensions

Constructors

Colour(int value)
Creates a colour from a 32-bit 0xAARRGGBB number, like Color.
const
Colour.fromARGB({required int alpha, required int red, required int green, required int blue})
Creates a colour from alpha, red, green and blue values between 0 and 255. An alpha of 0 is transparent and 255 is opaque.
const
Colour.fromB256(String data)
Reads a colour from the four-character string made by b256.
Colour.fromColor(Color color)
Creates a Colour from a Flutter Color.
Colour.fromFraction({double alpha = 1.0, double red = 1.0, double green = 1.0, double blue = 1.0})
Creates a colour from channel values between 0.0 and 1.0, the way Flutter stores them.
Colour.fromHex({required String hexString})
Parses a hex colour string, with or without a leading #.
factory
Colour.fromHSL({required double h, required double s, required double l})
Creates a colour from hue h (0 to 360), saturation s (0.0 to 1.0) and lightness l (0.0 to 1.0).
factory
Colour.fromHSLColour(HSLColour hslColour)
Converts an HSLColour to RGB.
factory
Colour.fromHSV({double a = 1.0, required double h, required double s, required double v})
Creates a colour from hue h (0 to 360), saturation s (0.0 to 1.0), value v (0.0 to 1.0) and opacity a (0.0 to 1.0, opaque by default).
factory
Colour.fromHSVColour(HSVColour hsvColour)
Converts an HSVColour to RGB.
factory
Colour.fromInt(int value)
Creates a colour from a 32-bit 0xAARRGGBB number. Same as Colour.new.
const
Colour.fromPercent({double a = 100, double r = 100, double g = 100, double b = 100})
Creates a colour from channel percentages between 0 and 100.
Colour.fromRGB({required int red, required int green, required int blue})
Creates a fully opaque colour from red, green and blue values between 0 and 255.
const

Properties

a → double
The alpha channel of this color.
no setteroverride
alpha → int
The alpha channel of this color in an 8 bit value.
final
alphaInt → int

Available on Color, provided by the ColourExtension extension

The alpha (opacity) channel, from 0 (transparent) to 255 (opaque).
no setter
argb → String
The channels as comma-separated numbers: 'alpha,red,green,blue'.
no setter
b → double
The blue channel of this color.
no setteroverride
b256 → String
This colour as a compact four-character string, one base-256 digit per channel. Read it back with Colour.fromB256.
no setter
blue → int
The blue channel of this color in an 8 bit value.
final
blueInt → int

Available on Color, provided by the ColourExtension extension

The blue channel, from 0 to 255.
no setter
color → Color
This colour as a plain Flutter Color.
no setter
colorSpace → ColorSpace
The color space of this color.
no setteroverride
colour → Colour

Available on Color, provided by the ColourExtension extension

This colour as a Colour.
no setter
g → double
The green channel of this color.
no setteroverride
green → int
The green channel of this color in an 8 bit value.
final
greenInt → int

Available on Color, provided by the ColourExtension extension

The green channel, from 0 to 255.
no setter
hashCode → int
The hash code for this object.
no setteroverride
hex → String
This colour as an eight-digit hex string in AARRGGBB order, without a #.
no setter
hsl → HSLColour
This colour as hue, saturation and lightness.
no setter
hsv → HSVColour
This colour as hue, saturation and value.
no setter
hsvValue → double
The HSV value (brightness), from 0.0 (black) to 1.0 (full brightness).
no setter
hue → double
The hue, from 0 to 360 degrees around the colour wheel (0 is red).
no setter
lightness → double
The HSL lightness, from 0.0 (black) through 0.5 (pure colour) to 1.0 (white).
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 of this color in an 8 bit value.
final
redInt → int

Available on Color, provided by the ColourExtension extension

The red channel, from 0 to 255.
no setter
rgb → String
The colour channels as comma-separated numbers: 'red,green,blue'.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
saturation → double
The HSV saturation, from 0.0 (grey) to 1.0 (fully vivid).
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
The same as b256.
toARGB32() → int
Returns a 32-bit value representing this color.
override
toColour() → Colour
This colour as an RGB Colour.
override
toHSL() → HSLColour
This colour as an HSLColour.
override
toHSLColor() → HSLColor
This colour as a Flutter HSLColor.
toHSV() → HSVColour
This colour as an HSVColour.
override
toHSVColor() → HSVColor
This colour as a Flutter 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
A copy of this colour with its HSV value (brightness) changed to value (0.0 to 1.0).
withHue(double hue) → Colour
A copy of this colour with its hue changed to hue (0 to 360).
withLightness(double lightness) → Colour
A copy of this colour with its HSL lightness changed to lightness (0.0 to 1.0).
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
A copy of this colour with its HSV saturation changed to saturation (0.0 to 1.0).
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