blend method

Color blend(
  1. Color other,
  2. double ratio
)

Blends the current color with another color using a specified blending ratio.

The blend method blends the current color and another color based on the given ratio. The ratio should be between 0 and 1, where 0 represents the first color (current color) and 1 represents the second color.

Example:

Color color1 = Color(0xFF42A5F5);
Color color2 = Color(0xFFFF5722);
Color blendedColor = color1.blend(color2, 0.5); // Blends 50% of both colors

Implementation

Color blend(Color other, double ratio) {
  assert(ratio >= 0 && ratio <= 1, 'Ratio should be between 0 and 1');
  return Color.fromARGB(
    (a * (1 - ratio) + other.a * ratio).toInt(),
    (r * (1 - ratio) + other.r * ratio).toInt(),
    (g * (1 - ratio) + other.g * ratio).toInt(),
    (b * (1 - ratio) + other.b * ratio).toInt(),
  );
}