estimateBrightnessForColor static method

Brightness estimateBrightnessForColor(
  1. Color color
)

Determines whether the given Color is Brightness.light or Brightness.dark.

Implementation

static Brightness estimateBrightnessForColor(Color color) {
  final double relativeLuminance = color.computeLuminance();
  const double kThreshold = 0.098;
  return ((relativeLuminance + 0.05) * (relativeLuminance + 0.05) >
          kThreshold)
      ? Brightness.light
      : Brightness.dark;
}