Color.fromHex constructor

Color.fromHex({
  1. required String code,
})

Construct the color from a hex code string, of the format #RRGGBB.

Implementation

factory Color.fromHex({required String code}) {
  var str = code.substring(1, 7);
  var bigint = int.parse(str, radix: 16);
  final r = (bigint >> 16) & 255;
  final g = (bigint >> 8) & 255;
  final b = bigint & 255;
  final a = 255;
  return Color(r: r, g: g, b: b, a: a);
}