HSLuvColor.fromColor constructor
Creates an HSLuvColor from an RGB Color.
When round is true (default), components are rounded to the nearest
integer. Pass round: false or use HSLuvColor.fromRawColor to preserve
full floating-point precision.
Implementation
factory fromColor(Color color, {bool round = true}) {
final double red = color.r.clamp(0.0, 1.0);
final double green = color.g.clamp(0.0, 1.0);
final double blue = color.b.clamp(0.0, 1.0);
final List<double> luv = Hsluv.rgbToHsluv([red, green, blue]);
final double hue = (round ? luv[0].roundToDouble() : luv[0]).clamp(
0.0,
360.0,
);
final double saturation = (round ? luv[1].roundToDouble() : luv[1]).clamp(
0.0,
100.0,
);
final double lightness = (round ? luv[2].roundToDouble() : luv[2]).clamp(
0.0,
100.0,
);
return HSLuvColor.fromHSL(hue, saturation, lightness);
}