ColorTools class Null safety

Static color tool functions used internally by FlexColorPicker.

The functions have a public API and can also be used on their own outside FlexColorPicker if so desired. Available functions include:

  • Get English name strings for the Material primary and accent colors.
  • Maps of color swatches to their names.
  • Functions to check if a given color belongs to a given color swatch.
  • Find the swatch a color belongs to.
  • Create material and accent like swatches of a single color.
  • Get the color name of a color belonging to a swatch and its swatch index.
  • A "name that color" function that gives an English name to any color.

The static color names are not const on purpose, they have default values for their English Material color names. If you need to translate them setup a function that modifies them as needed in your app, something simple like this may be all you need:

void main() {
  translateColorNames();
  runApp(const ColorPickerDemo());
}

void translateColorNames() {
ColorTools.redName = 'Röd';
ColorTools.blueName = 'Blå';
  :
}

In a translated app you would be using translated strings from your used translation tool, and call it whenever the used language is changed.

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent 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 Properties

accentColorsNames Map<ColorSwatch<Object>, String>
Map of Material accent color swatches and their names. [...]
read / write
amberAccentName String
Name of Material amber accent color. Default value is its English name.
read / write
amberName String
Name of Material amber color. Default value is its English name.
read / write
blackAndWhiteNames Map<ColorSwatch<Object>, String>
Map of black and white swatches, with their near black and white colors to the black and white swatch names. [...]
read / write
blackShadeName String
Name of black and near black color swatch. Default value is its English name.
read / write
blueAccentName String
Name of Material blue accent color. Default value is its English name.
read / write
blueGreyName String
Name of Material blue grey color. Default value is its English name.
read / write
blueName String
English name for Material blue color. Default value is its English name.
read / write
brownName String
Name of Material brown color. Default value is its English name.
read / write
cyanAccentName String
Name of Material cyan accent color. Default value is its English name.
read / write
cyanName String
Name of Material cyan color. Default value is its English name.
read / write
deepOrangeAccentName String
Name of Material deep orange accent color. Default value is its English name.
read / write
deepOrangeName String
Name of Material deep orange color. Default value is its English name.
read / write
deepPurpleAccentName String
Name of Material deep purple accent color. Default value is its English name.
read / write
deepPurpleName String
Name of Material deep purple color. Default value is its English name.
read / write
greenAccentName String
Name of Material green accent color. Default value is its English name.
read / write
greenName String
Name of Material green color. Default value is its English name.
read / write
greyName String
Name of Material grey color. Default value is its English name.
read / write
indigoAccentName String
Name of Material indigo accent color. Default value is its English name.
read / write
indigoName String
Name of Material indigo color. Default value is its English name.
read / write
lightBlueAccentName String
Name of Material light blue accent color. Default value is its English name.
read / write
lightBlueName String
Name of Material light blue color. Default value is its English name.
read / write
lightGreenAccentName String
Name of Material light green accent color. Default value is its English name.
read / write
lightGreenName String
Name of Material light green color. Default value is its English name.
read / write
limeAccentName String
Name of Material lime accent color. Default value is its English name.
read / write
limeName String
Name of Material lime color. Default value is its English name.
read / write
orangeAccentName String
Name of Material orange accent color. Default value is its English name.
read / write
orangeName String
Name of Material orange color. Default value is its English name.
read / write
pinkAccentName String
Name of Material pink accent color. Default value is its English name.
read / write
pinkName String
Name of Material pink color. Default value is its English name.
read / write
primaryColorNames Map<ColorSwatch<Object>, String>
Map of Material primary color swatches and their names. [...]
read / write
purpleAccentName String
Name of Material purple accent color. Default value is its English name.
read / write
purpleName String
English name for Material purple color. Default value is its English name.
read / write
redAccentName String
Name of Material red accent color. Default value is its English name.
read / write
redName String
Name of Material red color. Default value is its English name.
read / write
tealAccentName String
Name of Material teal accent color. Default value is its English name.
read / write
tealName String
Name of Material teal color. Default value is its English name.
read / write
whiteShadeName String
Name of white and near white color swatch. Default value is its English name.
read / write
yellowAccentName String
Name of Material yellow accent color. Default value is its English name.
read / write
yellowName String
Name of Material yellow color. Default value is its English name.
read / write

Static Methods

accentSwatch(Color color) MaterialAccentColor
Returns a Material accent color swatch for the color given to it. [...]
blackAndWhiteSwatch(Color color) ColorSwatch<Object>
Returns a black or white color swatch for the color given to it. [...]
colorCode(Color color) String
Return the color value as a HexCode string in uppercase.
createAccentSwatch(Color color) MaterialAccentColor
Create an Accent color swatch from a given single color value. [...]
createPrimarySwatch(Color color) MaterialColor
Create a primary color Material swatch from a given color value. [...]
customSwatch(Color color, Map<ColorSwatch<Object>, String>? customSwatch) ColorSwatch<Object>
Returns the custom color swatch for the color given to it. [...]
isAccentColor(Color color) bool
Check if the given color is included in any Material accent color swatch. [...]
isBlackAndWhiteColor(Color color) bool
Check if a color is included in the custom black and white swatches. [...]
isCustomColor(Color color, Map<ColorSwatch<Object>, String>? customSwatch) bool
Check if a color is included in a custom color swatches. [...]
isPrimaryColor(Color color) bool
Check if the given color is included in any Material primary color swatch. [...]
materialName(Color color, {Map<ColorSwatch<Object>, String>? colorSwatchNameMap, bool withIndex = true}) String
Returns the Material swatch name or custom color swatch name for a given color. [...]
materialNameAndARGBCode(Color color, {Map<ColorSwatch<Object>, String>? colorSwatchNameMap}) String
Returns the official Material color name for the color passed to it, including the shade index and ARGB style HexCode. [...]
materialNameAndCode(Color color, {Map<ColorSwatch<Object>, String>? colorSwatchNameMap}) String
Returns the official Material color name for the color passed to it, including the shade index and Flutter style HexCode. [...]
nameThatColor(Color color) String
Returns a String name of the color passed to it. [...]
primarySwatch(Color color) MaterialColor
Returns a Material primary color swatch for the color given to it. [...]
swatchContainsColor(ColorSwatch<Object> swatch, Color color) bool
Returns true if the swatch contains color. [...]

Constants

accentColors → const List<ColorSwatch<Object>>
List of all the standard Material accent color swatches. [...]
<ColorSwatch<Object>>[Colors.redAccent, Colors.pinkAccent, Colors.purpleAccent, Colors.deepPurpleAccent, Colors.indigoAccent, Colors.blueAccent, Colors.lightBlueAccent, Colors.cyanAccent, …
blackAndWhite → const List<ColorSwatch<Object>>
The blackShade and whiteShade in a color swatch list.
<ColorSwatch<Object>>[blackShade, whiteShade]
blackShade → const ColorSwatch<Object>
A color swatch for almost black colors, ending in black. [...]
ColorSwatch<Object>(0xFF0A0A0A, <int, Color>{50 : Color(0xFF121212), 100 : Color(0xFF111111), 200 : Color(0xFF101010), 300 : Color(0xFF0E0E0E), 400 : Color(0xFF0C0C0C), 500 : Color(0xFF0A0…
primaryAndAccentColors → const List<ColorSwatch<Object>>
A list with both primary and accent color Material color swatches. [...]
<ColorSwatch<Object>>[Colors.red, Colors.redAccent, Colors.pink, Colors.pinkAccent, Colors.purple, Colors.purpleAccent, Colors.deepPurple, Colors.deepPurpleAccent, Colors.indigo, Colors.in…
primaryColors → const List<ColorSwatch<Object>>
List of all the standard Material primary color swatches. [...]
<ColorSwatch<Object>>[Colors.red, Colors.pink, Colors.purple, Colors.deepPurple, Colors.indigo, Colors.blue, Colors.lightBlue, Colors.cyan, Colors.teal, Colors.green, Colors.lightGreen, Co…
whiteShade → const ColorSwatch<Object>
A color swatch for almost white colors, starting with white. [...]
ColorSwatch<Object>(0xFFFAFAFB, <int, Color>{50 : Color(0xFFFFFFFF), 100 : Color(0xFFFEFEFE), 200 : Color(0xFFFDFDFD), 300 : Color(0xFFFCFCFC), 400 : Color(0xFFFBFBFB), 500 : Color(0xFFFAF…