ColorTools class

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.
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 Properties

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

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.
blackAndWhite → const List<ColorSwatch<Object>>
The blackShade and whiteShade in a color swatch list.
blackShade → const ColorSwatch<Object>
A color swatch for almost black colors, ending in black.
primaryAndAccentColors → const List<ColorSwatch<Object>>
A list with both primary and accent color Material color swatches.
primaryColors → const List<ColorSwatch<Object>>
List of all the standard Material primary color swatches.
whiteShade → const ColorSwatch<Object>
A color swatch for almost white colors, starting with white.