Skip to main content
1

💡 Accessibility & Contrast

luminance
double
The relative luminance of the color (0.0=black, 1.0=white). Essential for contrast calculations.
final lum = myColor.luminance; // 0.0 - 1.0
isDark
bool
Checks if the color is perceived as dark (luminance < 0.5). Use this to decide if white text should be used.
final needsWhiteText = Colors.black.isDark; // true
isLight
bool
Checks if the color is perceived as light (luminance ≥ 0.5). Use this to decide if dark text should be used.
final needsDarkText = Colors.yellow.isLight; // true
2

⚙️ Manipulation & Conversion

getLighterShade(double factor)
Color
Lightens the color by a specified factor (0.0 to 1.0). Alpha channel is preserved.
final lighterBlue = Colors.blue.getLighterShade(0.2);
toHex({bool hashSign, bool withAlpha})
String
Converts the color to its hexadecimal string representation.
// Returns #2196F3;
Colors.blue.toHex();
3

🎨 The Swatch Creator

toMaterialColor
MaterialColor
Generates a full 10-shade MaterialColor swatch (50-900) from a single base color. The ultimate shortcut for ThemeData.primarySwatch.
final customSwatch = Color(0xFF1ABC9C).toMaterialColor;