cssColorArgb function

String cssColorArgb(
  1. int argb
)

Formats an ARGB integer as lowercase CSS hexadecimal.

Opaque colors use #rrggbb; colors carrying alpha use #rrggbbaa, following CSS ordering rather than the input integer's ARGB ordering.

Implementation

String cssColorArgb(int argb) {
  final rgb = (argb & 0xFFFFFF).toRadixString(16).padLeft(6, '0');
  final alpha = (argb >> 24) & 0xFF;
  return alpha == 0xFF
      ? '#$rgb'
      : '#$rgb${alpha.toRadixString(16).padLeft(2, '0')}';
}