textLuminance function

Color textLuminance(
  1. Color backgroundColor
)

A helper function for determining what color to use in a Text widget based on a given background color.

Useful for ensuring that text is readable on a given background color.

This is most useful when the given background color is unknown. For example, the GitHub API provides colors for programming languages, and you can have an Array of languages. If you want to construct widgets to represent the languages and have the text color be readable, this function is quite helpful.

Implementation

Color textLuminance(Color backgroundColor) {
  return backgroundColor.computeLuminance() > 0.5 ? Colors.black : Colors.white;
}