colorToHex function
Converts dart:ui
Color to the 6/8 digits HEX String.
Prefixes a hash (#
) sign if includeHashSign
is set to true
.
The result will be provided as UPPER CASE, it can be changed via toUpperCase
flag set to false
(default is true
). Hex can be returned without alpha
channel information (transparency), with the enableAlpha
flag set to false
.
Implementation
String colorToHex(
Color color, {
bool includeHashSign = false,
bool enableAlpha = true,
bool toUpperCase = true,
}) {
final String hex = (includeHashSign ? '#' : '') +
(enableAlpha ? _padRadix(color.alpha) : '') +
_padRadix(color.red) +
_padRadix(color.green) +
_padRadix(color.blue);
return toUpperCase ? hex.toUpperCase() : hex;
}