SpringSimulation class

A spring simulation.

Models a particle attached to a spring that follows Hooke's law.

This method triggers an AnimationController (a previously constructed _controller field) to simulate a spring oscillation.
link
void _startSpringMotion() {
  _controller.animateWith(SpringSimulation(
    const SpringDescription(
      mass: 1.0,
      stiffness: 300.0,
      damping: 15.0,
    ),
    0.0, // starting position
    1.0, // ending position
    0.0, // starting velocity
  ));
}

This AnimationController could be used with an AnimatedBuilder to animate the position of a child as if it were attached to a spring.

Inheritance
Implementers

Constructors

SpringSimulation(SpringDescription spring, double start, double end, double velocity, {Tolerance tolerance = Tolerance.defaultTolerance})
Creates a spring simulation from the provided spring description, start distance, end distance, and initial velocity.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tolerance Tolerance
How close to the actual end of the simulation a value at a particular time must be before isDone considers the simulation to be "done".
getter/setter pairinherited
type SpringType
The kind of spring being simulated, for debugging purposes.
no setter

Methods

dx(double time) double
The velocity of the object in the simulation at the given time.
override
isDone(double time) bool
Whether the simulation is "done" at the given time.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override
x(double time) double
The position of the object in the simulation at the given time.
override

Operators

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