colorParse function

Color colorParse(
  1. dynamic value
)

This will parse either a string or integer representation of a color into an actual Color

Implementation

Color colorParse(dynamic value) {
  // input is string (e.g. 'FF112233') convert to integer
  if (value is String) {
    if (value.toString().length == 6) value = 'FF' + value.toString();
    value = int.parse(value.toString(), radix: 16);
  }

  // input is integer (e.g. 0xFF112233) convert to color
  if (value is int) {
    return Color(value).withOpacity(1.0);
  }

  throw Exception('Failed to convert $value to Color');
}