hexToColor function Misc Utils

Color hexToColor(
  1. String hexString
)

String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".

Implementation

Color hexToColor(String hexString) {
  final buffer = StringBuffer();
  if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
  buffer.write(hexString.replaceFirst('#', ''));

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