darker method

HTMLColor? darker([
  1. int? amount,
  2. HTMLColor? def
])

Returns a darker color using amount (from 0 to 255) to decrease bright.

def The default color to return if it's not possible to generate a darker color.

Implementation

HTMLColor? darker([int? amount, HTMLColor? def]) {
  var space = getDarkerSpace();
  if (def != null && space <= 2) return def;

  amount ??= _colorChangeAmount(space);

  var minAmount = Math.min(amount ~/ 2, 10);

  if (space < amount) {
    if (space < minAmount) return def;
    amount = space;
  }

  return HTMLColor(_clip(red - amount), _clip(green - amount),
      _clip(blue - amount), alpha);
}