toColor method

Color? toColor()

Converts a hex color string to a Color. Returns null if the string is not a valid hex color.

Implementation

Color? toColor() {
  if (!isHexColor) return null;
  var hex = replaceAll('#', '');
  if (hex.length == 3) {
    hex = hex.split('').map((c) => '$c$c').join();
  }
  return Color(int.parse('FF$hex', radix: 16));
}