contrastColor property

Color get contrastColor

Returns Colors.black or Colors.white depending on the color's brightness.

Edge Case: If the color is highly transparent (alpha < 0.2), it assumes a light background and returns black for visibility.

Implementation

Color get contrastColor {
  if (a < 0.2) return Colors.black;
  return computeLuminance() > 0.5 ? Colors.black : Colors.white;
}