clamped method

double clamped({
  1. required double min,
  2. required double max,
})

Clamps this double between min and max.

Returns a value that is at least min and at most max.

Example:

double value = 150.5;
value = value.clamped(min: 0.0, max: 100.0); // 100.0

Implementation

double clamped({required double min, required double max}) {
  if (this < min) return min;
  if (this > max) return max;
  return this;
}