intColor static method

int intColor(
  1. String? colorString
)

Parse the color string, and return the corresponding color-int. If the string cannot be parsed, throws an ArgumentError

Implementation

static int intColor(String? colorString) {
  if (colorString?.isEmpty ?? true) {
    throw ArgumentError('Unknown color');
  }
  if (colorString![0] == '#') {
    int? color = int.tryParse(colorString.substring(1), radix: 16);
    if (colorString.length == 7 && color != null) {
      // Set the alpha value
      color |= 0x00000000ff000000;
    } else if (colorString.length != 9) {
      throw ArgumentError('Unknown color');
    }
    return color!;
  } else {
    int? color = sColorNameMap[(colorString.toLowerCase())];
    if (color != null) {
      return color;
    } else {
      return intColor('#' + colorString);
    }
  }
}