toHex method
String
toHex(
{ - bool leadingHashSign = true,
- 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';
}