applyRubberBandResistance static method
Applies iOS-style rubber band resistance when dragging beyond edges.
Values outside the 0-1 range are compressed with decreasing resistance, creating a "pulling against rubber band" feel.
Parameters:
value: The normalized drag position (typically 0-1, but can exceed)resistance: Lower values = more resistance (default: 0.4)maxOverdrag: Maximum overdrag as fraction of range (default: 0.3)
Returns: Adjusted value with rubber band resistance applied.
Example:
final adjusted = DraggableIndicatorPhysics.applyRubberBandResistance(1.5);
// Returns approximately 1.2 instead of 1.5
Implementation
static double applyRubberBandResistance(
double value, {
double resistance = 0.4,
double maxOverdrag = 0.3,
}) {
if (value < 0) {
// Overdrag to the left
final overdrag = -value;
final resistedOverdrag = overdrag * resistance;
return -resistedOverdrag.clamp(0.0, maxOverdrag);
} else if (value > 1) {
// Overdrag to the right
final overdrag = value - 1;
final resistedOverdrag = overdrag * resistance;
return 1 + resistedOverdrag.clamp(0.0, maxOverdrag);
}
// Normal range, no resistance
return value;
}