colorToHex function
Converts a Flutter Color to a hex string.
Options:
includeHashSign— Prepend#to the output.enableAlpha— Include the alpha channel in the output.toUpperCase— Return the hex in uppercase (default:true).
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;
}