getTextColor method

Color getTextColor(
  1. String label
)

Returns an appropriate text color (white or black) for the background color assigned to the given label to ensure legible contrast

Implementation

Color getTextColor(String label) {
  final background = getColor(label);
  final isDark = background.computeLuminance() < 0.05;
  return isDark ? Colors.white : Colors.black;
}