getContrastColor function
Color
getContrastColor(
- Color color, {
- Color backgroundColor = Colors.white,
})
Implementation
Color getContrastColor(Color color, {Color backgroundColor = Colors.white}) {
// Blend the input color with the background color
Color blendedColor = Color.alphaBlend(color, backgroundColor);
double luminance = blendedColor.computeLuminance();
// If the color is light, return black, otherwise return white
if (luminance > 0.5) {
return Colors.black;
} else {
return Colors.white;
}
}