FrictionSim class

A friction-based simulation that decelerates exponentially.

Models scroll flings, swipe releases, and any motion that slows down due to air resistance or surface friction.

Position formula: x(t) = x₀ + v₀ · (drag^t - 1) / ln(drag)

Usage:

final sim = FrictionSim(position0: 0.0, velocity0: 500.0);
final pos = sim.position(0.3); // position at t=0.3 seconds
Inheritance

Constructors

FrictionSim({required double position0, required double velocity0, double drag = 0.135, double restVelocityThreshold = 1.0})

Properties

drag double
Drag coefficient 0.0, 1.0. Lower = more friction, faster stop. Default 0.135 (matches Flutter's BouncingScrollPhysics).
final
hashCode int
The hash code for this object.
no setterinherited
id String
Unique identifier for this simulator type.
no setteroverride
position0 double
Initial position.
final
restVelocityThreshold double
Rest velocity threshold below which motion is considered stopped.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stopTime double
Estimated stop time (when velocity < threshold).
no setter
totalDistance double
Total distance traveled until rest.
no setter
velocity0 double
Initial velocity (units/sec).
final

Methods

isDone(double t) bool
True when the simulation has effectively come to rest.
override
normalized(double t, {required double from, required double to}) double
Normalizes position to 0.0, 1.0 based on from and to. Useful for driving AnimationController.value.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
position(double t) double
Position at time t (seconds).
override
sample({double durationSec = 2.0, int sampleHz = 60}) List<double>
Samples the simulation at sampleHz for durationSec seconds.
inherited
settleDuration({double maxTime = 10.0, int resolution = 120}) double
Returns the time (seconds) at which isDone first becomes true, sampled at resolution steps per second. Returns maxTime if never done.
inherited
toString() String
A string representation of this object.
override
velocity(double t) double
Velocity at time t (units/second).
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

android({required double velocity0}) FrictionSim
Android-like scroll physics.
heavy({required double velocity0}) FrictionSim
Heavy surface — quick stop.
ios({required double velocity0}) FrictionSim
iOS scroll physics drag coefficient.