toGrayscale method
Converts the current color to a grayscale color by averaging the red, green, and blue channels.
Example:
Color color = Color(0xFF42A5F5);
Color grayScale = color.toGrayscale();
print(grayScale); // Output: a grayscale version of the color.
Implementation
Color toGrayscale() {
int gray = ((r + g + b) / 3).round();
return Color.fromARGB(a.toInt(), gray, gray, gray);
}