hexToInt static method

int hexToInt(
  1. String hex
)

Converts the given hex color string to the corresponding int.

Note that when no alpha/opacity is specified, 0xFF is assumed.

Implementation

static int hexToInt(String hex) {
  final hexDigits = hex.startsWith('#') ? hex.substring(1) : hex;
  final hexMask = hexDigits.length <= 6 ? 0xFF000000 : 0;
  final hexValue = int.parse(hexDigits, radix: 16);
  assert(hexValue >= 0 && hexValue <= 0xFFFFFFFF);
  return hexValue | hexMask;
}