subtle method

Color subtle([
  1. double amount = 0.06,
  2. double darkenLimit = 0.2
])

Find a subtle variant of a color (for example, for displaying hover states).

The amount (defaults to 0.06) is substracted from color lightness is lightness if greater than darkenLimit (defaults to 0.2), else it is added to color lightness.

Implementation

Color subtle([double amount = 0.06, double darkenLimit = 0.2]) {
  final hsl = HSLColor.fromColor(this);
  if (hsl.lightness > darkenLimit) {
    amount *= -1.0;
  }

  if (_isWhiteOrBlack) {
    final v = (red + amount * 255).round().clamp(0, 255);
    return Color.fromARGB(alpha, v, v, v);
  }

  return hsl
      .withLightness(
        (hsl.lightness + amount).clamp(0.0, 1.0),
      )
      .toColor();
}