IrColor.fromHex constructor

IrColor.fromHex(
  1. String hex, {
  2. String? token,
})

Parses #RRGGBB or #RRGGBBAA.

Implementation

factory IrColor.fromHex(String hex, {String? token}) {
  final h = hex.startsWith('#') ? hex.substring(1) : hex;
  if (h.length != 6 && h.length != 8) {
    throw FormatException('Bad color: $hex');
  }
  int c(int i) => int.parse(h.substring(i, i + 2), radix: 16);
  return IrColor._(
    c(0) / 255,
    c(2) / 255,
    c(4) / 255,
    h.length == 8 ? c(6) / 255 : 1,
    token,
  );
}