fromARGBHexString static method

Color fromARGBHexString(
  1. String hexString
)

Parses an ARGB color from a valid hex string (e.g. #1C1C1C).

The # is optional. The short-hand syntax is support, e.g.: #CCCC. Lower-case letters are supported.

Examples of valid inputs: fccc, FCCC, #fccc, #FCCC, #ffc1c1c1, #FFC1C1C1, ffc1c1c1, FFC1C1C1

If the string is not valid, an error is thrown.

Note: if you are hardcoding colors, use Dart's built-in hexadecimal literals instead.

Implementation

static Color fromARGBHexString(String hexString) {
  if (hexString.length == 4 || hexString.length == 5) {
    return _parseRegex(1, 4, hexString);
  } else if (hexString.length == 8 || hexString.length == 9) {
    return _parseRegex(2, 4, hexString);
  } else {
    throw 'Invalid format for ARGB hex string: $hexString';
  }
}