Skip to main content

Module simulation

Module simulation 

Source
Expand description

Concrete Simulation curves — the ballistic motion a ScrollPhysics hands back once a gesture releases.

Four ports of Flutter’s scroll math, formulas and tuning constants carried over unchanged so a frust fling lands where the platform’s own would: physics/friction_simulation.dart (FrictionSimulation), physics/spring_simulation.dart (SpringSimulation, ScrollSpringSimulation) and widgets/scroll_simulation.dart (ClampingScrollSimulation, BouncingScrollSimulation) — the last two being in turn ports of Android’s SplineOverScroller curve and iOS’s UIScrollView friction-then-rubber-band behavior. Every tuning constant is stated as the expression its source states it as (never a transcribed decimal) and pinned by a test in this file.

Time is in seconds from each simulation’s own start, per the Simulation contract; a simulation carries the Tolerance it settles within as a constructor argument rather than reading one per call.

Structs§

BouncingScrollSimulation
iOS’s fling: exponential friction while the position is in range, handing over to a rubber-band spring at whichever edge the fling reaches.
ClampingScrollSimulation
Android’s fling curve — the SplineOverScroller deceleration a clamping scroll surface runs after a release, which decays to a hard stop at a known duration and distance rather than an asymptote.
FrictionSimulation
Exponential drag decay: the iOS-style fling curve, and the friction phase of BouncingScrollSimulation.
ScrollSpringSimulation
A SpringSimulation that reports exactly end once settled, rather than the residual sub-tolerance displacement the closed form still carries.
SpringSimulation
A damped spring settling from start onto end, solving m·ẍ + c·ẋ + k·x = 0 on the displacement between them.

Enums§

SpringType
Which closed-form solution a SpringSimulation resolved to, decided by damping² − 4·mass·stiffness.