toHex method

String toHex({
  1. bool withAlpha = true,
  2. bool includeHashSign = true,
})

Returns the hex string representation of this color

Implementation

String toHex({bool withAlpha = true, bool includeHashSign = true}) {
  String prefix = includeHashSign ? '#' : '';

  if (withAlpha) {
    return '$prefix${value.toRadixString(16).padLeft(8, '0').toUpperCase()}';
  } else {
    return '$prefix${value.toRadixString(16).padLeft(8, '0').substring(2).toUpperCase()}';
  }
}