toHex method

String toHex({
  1. bool leadingHashSign = true,
  2. bool includeAlpha = false,
})

Implementation

String toHex({bool leadingHashSign = true, bool includeAlpha = false}) {
  final r =
      ((this.r * 255.0).round() & 0xff).toRadixString(16).padLeft(2, '0');
  final g =
      ((this.g * 255.0).round() & 0xff).toRadixString(16).padLeft(2, '0');
  final b =
      ((this.b * 255.0).round() & 0xff).toRadixString(16).padLeft(2, '0');
  final a =
      ((this.a * 255.0).round() & 0xff).toRadixString(16).padLeft(2, '0');
  final hash = leadingHashSign ? '#' : '';
  return includeAlpha ? '$hash$r$g$b$a' : '$hash$r$g$b';
}