stringToColor static method

Color stringToColor(
  1. String textString
)

Implementation

static Color stringToColor(String textString) {
  var text = textString.replaceFirst('#', '');
  if (text.length == 3) {
    text = text.replaceAllMapped(
        RegExp(r"[a-f]|\d", caseSensitive: false),
        (match) => '${match.group(0)}${match.group(0)}'
    );
  }
  if (text.length > 6) {
    text = "0x$text";
  } else {
    text = "0xFF$text";
  }
  return Color(int.parse(text));
}