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}) {
  final str = code.substring(1, 7);
  final bigint = int.parse(str, radix: 16);
  final r = (bigint >> 16) & 255;
  final g = (bigint >> 8) & 255;
  final b = bigint & 255;
  return Color(r: r, g: g, b: b);
}