formatHex function
Formats RGB channels (0–255) as an uppercase #RRGGBB string.
Implementation
String formatHex(double r, double g, double b) {
String channel(double c) => clampDouble(
c.roundToDouble(),
0,
255,
).toInt().toRadixString(16).padLeft(2, '0').toUpperCase();
return '#${channel(r)}${channel(g)}${channel(b)}';
}