toCssHexColor function
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(double channelValue) =>
(channelValue * 255).round().toRadixString(16).padLeft(2, '0');
return '#${hex(color.r)}${hex(color.g)}${hex(color.b)}${hex(color.a)}';
}