colorToString method
Converts a Color object to a CSS-compatible hex color string in the format #RRGGBB.
This function ignores the alpha channel (opacity), making it suitable for contexts that expect opaque colors (e.g., HTML/CSS attributes, web widgets).
Example:
Colors.red→"#FF0000"Color(0xFFFF5722)→"#FF5722"
Note: If transparency is required, consider using an rgba() format instead.
Implementation
String colorToString(Color color) {
return '#${color.toARGB32().toRadixString(16).padLeft(8, '0').substring(2).toUpperCase()}';
}