withValues method
Returns the Color as a semi-transparent version of itself based on the provided opacity factor.
The opacity factor should be between 0.0 (fully transparent) and 1.0 (fully opaque).
Example:
Color color = Color(0xFF42A5F5);
Color semiTransparent = color.withValues(opacity: 0.5); // 50% opacity
Implementation
Color withValues({required double opacity}) {
assert(
opacity >= 0.0 && opacity <= 1.0,
'Opacity must be between 0.0 and 1.0',
);
return Color.fromARGB(
(a * opacity).toInt(),
r.toInt(),
g.toInt(),
b.toInt(),
);
}