scale method

Color scale({
  1. double alpha = 0.0,
  2. double hue = 0.0,
  3. double saturation = 0.0,
  4. double lightness = 0.0,
})

Scale color attributes relatively to current ones. alpha, hue, saturation and lightness values must be clamped between -1.0 and 1.0

Implementation

Color scale({
  double alpha = 0.0,
  double hue = 0.0,
  double saturation = 0.0,
  double lightness = 0.0,
}) {
  assert(alpha >= -1.0 && alpha <= 1.0);
  assert(hue >= -1.0 && hue <= 1.0);
  assert(saturation >= -1.0 && saturation <= 1.0);
  assert(lightness >= -1.0 && lightness <= 1.0);

  final hslColor = _getPatchedHslColor();

  double scale(double value, double amount, [double upperLimit = 1.0]) {
    var result = value;

    if (amount > 0) {
      result = value + (upperLimit - value) * amount;
    } else if (amount < 0) {
      result = value + value * amount;
    }

    return result.clamp(0.0, upperLimit);
  }

  return hslColor
      .withAlpha(scale(opacity, alpha))
      .withHue(scale(hslColor.hue, hue, 360.0))
      .withSaturation(scale(hslColor.saturation, saturation))
      .withLightness(scale(hslColor.lightness, lightness))
      .toColor();
}