createColorFromHEX function

Color createColorFromHEX(
  1. String hexString
)

Return a Color from a Hex string.

Implementation

Color createColorFromHEX(String hexString) {
  final buffer = StringBuffer();
  final hexWithoutHash = hexString.replaceFirst('#', '');

  if (hexWithoutHash.length == 6) {
    buffer.write('ff');
  }

  if (hexWithoutHash.length == 3) {
    buffer.write('ff');
    buffer.write(hexWithoutHash.splitMapJoin('', onNonMatch: (m) => m * 2));
  } else {
    buffer.write(hexWithoutHash);
  }

  return Color(int.parse(buffer.toString(), radix: 16));
}