toCssHexColor function

String toCssHexColor(
  1. Color color
)

Converts a dart:ui Color into #RRGGBBAA format for use in CSS.

Implementation

String toCssHexColor(Color color) {
  // In CSS Hex, Alpha comes last, but in Flutter's `value` field, alpha is
  // in the high bytes, so just using `value.toRadixString(16)` will put alpha
  // in the wrong position.
  String hex(int val) => val.toRadixString(16).padLeft(2, '0');
  return '#${hex(color.red)}${hex(color.green)}${hex(color.blue)}${hex(color.alpha)}';
}