HSVColor.fromColor constructor Null safety
- Color color
Creates an HSVColor from an RGB Color.
This constructor does not necessarily round-trip with toColor because of floating point imprecision.
Implementation
factory HSVColor.fromColor(Color color) {
final double red = color.red / 0xFF;
final double green = color.green / 0xFF;
final double blue = color.blue / 0xFF;
final double max = math.max(red, math.max(green, blue));
final double min = math.min(red, math.min(green, blue));
final double delta = max - min;
final double alpha = color.alpha / 0xFF;
final double hue = _getHue(red, green, blue, max, delta);
final double saturation = max == 0.0 ? 0.0 : delta / max;
return HSVColor.fromAHSV(alpha, hue, saturation, max);
}