brightness method
Returns a new Color with its brightness adjusted.
The amount must be between 0.0 and 1.0:
0.5(or1/2) leaves the brightness unchanged.- Less than
0.5makes the color darker. - Greater than
0.5makes the color brighter.
Example:
color.brightness(0.2); // Darker
color.brightness(0.8); // Brighter
Implementation
Color brightness(double amount) {
final hsl = HSLColor.fromColor(this);
final double delta = (amount.clamp(0.0, 1.0) - 0.5) * 2;
final double adjustedLightness = (hsl.lightness + delta).clamp(0.0, 1.0);
return hsl.withLightness(adjustedLightness).toColor();
}