enforceColor function
Returns a color that is closer to the specified color, with a brightness
value that is adjusted by percent
.
Implementation
Color enforceColor(Color color, [double percent = 0.2]) {
final brightness = color.computeLuminance();
const threshold = 0.5;
if (brightness == threshold) return color;
final newBrightness =
(brightness + (brightness > threshold ? percent : -percent))
.clamp(0.0, 1.0);
return color.withLightness(newBrightness);
}