DiscordColor.parseHexString constructor

DiscordColor.parseHexString(
  1. String color
)

Parse a string value to a DiscordColor.

color must be a valid 6-digit hexadecimal integer, optionally prefixed by a # symbol.

Implementation

factory DiscordColor.parseHexString(String color) {
  if (color.isEmpty) {
    throw FormatException('Source cannot be empty', color, 0);
  }

  if (color.startsWith('#')) {
    color = color.substring(1);
  }

  if (color.length != 6) {
    throw FormatException('Source must contain 6 hexadecimal digits', color, color.length);
  }

  return DiscordColor(int.parse(color, radix: 16));
}