Argb.parse constructor

Argb.parse(
  1. String hex
)

Implementation

factory Argb.parse(String hex) {
  var h = hex.trim().replaceFirst('#', '').toUpperCase();
  if (h.length == 6) h = 'FF$h';
  if (h.length != 8) {
    throw FormatException('Invalid color "$hex". Use #RRGGBB or #AARRGGBB.');
  }
  final value = int.parse(h, radix: 16);
  return Argb(
    (value >> 24) & 0xFF,
    (value >> 16) & 0xFF,
    (value >> 8) & 0xFF,
    value & 0xFF,
  );
}