formatHex function

String formatHex(
  1. double r,
  2. double g,
  3. double b
)

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)}';
}