fromRGBHexString static method
Parses an RGB color from a valid hex string (e.g. #1C1C1C).
The #
is optional.
The short-hand syntax is support, e.g.: #CCC.
Lower-case letters are supported.
Examples of valid inputs: ccc, CCC, #ccc, #CCC, #c1c1c1, #C1C1C1, c1c1c1, C1C1C1
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 fromRGBHexString(String hexString) {
if (hexString.length == 3 || hexString.length == 4) {
return _parseRegex(1, 3, hexString);
} else if (hexString.length == 6 || hexString.length == 7) {
return _parseRegex(2, 3, hexString);
} else {
throw 'Invalid format for RGB hex string: $hexString';
}
}