Flutter's Physics Simulations: The Simulation Class
Flutter's Simulation class is the engine for physics-based animations, modeling a 1D object's position and velocity over time. It powers realistic scrolling, springs, and gravity effects.
Why it exists
To move beyond static, pre-defined animation curves and enable animations that feel natural and respond dynamically to user input or changing conditions. The Simulation class allows developers to describe motion in terms of physical forces like friction or gravity, rather than fixed start and end points.
The mental model
A Simulation is a tiny, one-dimensional physics engine. You give it a time t, and it tells you exactly where an object is (x(t)) and how fast it's moving (dx(t)). It's the blueprint for behaviors like a ball rolling to a stop (FrictionSimulation) or a spring oscillating (SpringSimulation).
How it works
Simulation is an abstract class; you use a concrete implementation like SpringSimulation or create your own. The core contract is providing three methods: x(time) for position, dx(time) for velocity, and isDone(time) to check if it has settled. An AnimationController typically provides the elapsed time on each frame, and the simulation calculates the result. The system is unit-agnostic; you must establish a convention for distance and velocity (e.g., pixels and pixels-per-second) and use it consistently. The tolerance property defines how close to rest the object must be for isDone to return true.
When to use it
Use it when you need motion that feels physically plausible and responsive. This is ideal for scroll physics (like BouncingScrollSimulation), creating springy UI elements that overshoot and settle, or animating an object under the influence of gravity. It's the go-to for animations that are not simple A-to-B transitions.
When not to use it
For simple, fixed-duration, A-to-B animations with a predictable path, a standard Tween with a Curve is simpler and more performant. If your animation must follow a precise, non-physical timing, a Simulation adds unnecessary complexity.
One canonical example
Flinging a scrollable list. A FrictionSimulation is initiated with the fling's velocity. On each frame, the animation system asks the simulation for the new scroll offset based on elapsed time and a friction coefficient, creating a realistic slowdown. If you overscroll on iOS, a BouncingScrollSimulation might take over to create the rubber-band effect. This is all powered by the Simulation class via ScrollPhysics.
Interview question
When is Flutter's Simulation class the most appropriate choice for an animation?
- a.To define a simple, fixed-duration transition between two specific values.
- b.When an animation needs to follow a precise, non-physical timing curve.
- c.When the animation requires physically plausible motion that responds dynamically to conditions.Correct
- d.For animations that only involve changes in non-spatial properties like color or opacity.
Why? this is the answer
The Simulation class is designed for animations that need to feel natural and respond dynamically, modeling motion based on physical forces. Options A and B describe scenarios where a standard Tween with a Curve would be simpler and more appropriate, as explicitly stated in the card's 'WHEN NOT TO USE IT' section.
Just read this? Test yourself on what you have been reading.
Read the original → api.flutter.dev
- #flutter
- #dart
- #animation
- #physics
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on flutter — each one lists the topics its interview covers.
See open roles