rubberBand static method

double rubberBand(
  1. double offset, {
  2. required double limit,
  3. double tension = 1.0,
})

iOS's rubber-band curve: direct at first, asymptotically stiffer.

f(x) = (1 - 1/(x·tension/limit + 1))·limit — the platform's over-scroll shape, and the progressive sibling of SheetGeometry.applyResistance, whose flat multiplier cannot express "free at first, heavier further on". tension is the slope at the origin (1.0 = direct manipulation at first; iOS's over-scroll 0.55 would read as lag here, where the finger has not hit a wall yet). The result never passes limit.

Implementation

static double rubberBand(
  double offset, {
  required double limit,
  double tension = 1.0,
}) {
  if (limit <= 0.0) return 0.0;
  final magnitude = offset.abs();
  final damped = (1.0 - 1.0 / (magnitude * tension / limit + 1.0)) * limit;
  return offset.isNegative ? -damped : damped;
}