kipluo
Flutter8 min read4 steps

Flutter Spring Animation Basics

Curves like Curves.easeOut always take the same time and ignore how fast the user's finger was moving. A spring simulation starts from the current position and velocity and settles on its own schedule. This guide builds a draggable box that springs back, and explains the three numbers that define a spring.

You needFlutter 3.xStatefulWidget and AnimationControllerGestureDetector
Loading demo
The web version of Jelly Checkbox. Its squash and settle come from a spring with stiffness 260 and damping 14.Component page

1. Curves versus springs

A Tween with a Curve maps time to progress: 300 ms later you are at the end, whatever happened before. That's fine for a fade, but when the user flings something and lets go, a curve starts from zero velocity and the motion visibly stalls.

A spring is a physics model: a force pulls the value toward a target (stiffness) while friction slows it down (damping). Because it starts from the current velocity, a fling continues naturally into the settle. Flutter ships the model in package:flutter/physics.dart.

  • stiffness: how strongly it pulls toward the target. Higher is faster.
  • damping: how much motion is lost each moment. Lower means more overshoot and bounce.
  • mass: how heavy the object is. Usually left at 1; raise it to make motion feel slower and heavier.

2. A draggable box that springs back

AnimationController.unbounded lets the value go past 0 and 1, which spring overshoot needs. While dragging, the finger sets the offset directly. On release, a SpringSimulation starts at the current offset with the fling velocity from DragEndDetails and pulls back to 0.

spring_back_box.dart
import 'package:flutter/material.dart';
import 'package:flutter/physics.dart';

class SpringBackBox extends StatefulWidget {
  const SpringBackBox({super.key});

  @override
  State<SpringBackBox> createState() => _SpringBackBoxState();
}

class _SpringBackBoxState extends State<SpringBackBox> with SingleTickerProviderStateMixin {
  static const _spring = SpringDescription(mass: 1, stiffness: 260, damping: 14);

  late final AnimationController _controller = AnimationController.unbounded(vsync: this)
    ..addListener(() => setState(() => _offset = _controller.value));

  double _offset = 0;

  void _onDragUpdate(DragUpdateDetails details) {
    _controller.stop(); // grabbing mid-animation takes over immediately
    setState(() => _offset += details.delta.dx);
  }

  void _onDragEnd(DragEndDetails details) {
    final velocity = details.velocity.pixelsPerSecond.dx;
    final reduceMotion = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
    if (reduceMotion) {
      setState(() => _offset = 0);
      return;
    }
    _controller.animateWith(SpringSimulation(_spring, _offset, 0, velocity));
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onHorizontalDragUpdate: _onDragUpdate,
      onHorizontalDragEnd: _onDragEnd,
      child: Transform.translate(
        offset: Offset(_offset, 0),
        child: Container(
          width: 96,
          height: 96,
          decoration: BoxDecoration(
            color: Theme.of(context).colorScheme.primary,
            borderRadius: BorderRadius.circular(20),
          ),
        ),
      ),
    );
  }
}

3. Choosing stiffness and damping

A spring stops overshooting once damping reaches the critical value 2 × √(stiffness × mass). For stiffness 260 and mass 1 that is about 32, so damping 14 gives a visible bounce, and damping 30 or more settles without one.

If you prefer to think in bounce rather than raw damping, SpringDescription.withDampingRatio(mass: 1, stiffness: 260, ratio: 0.5) takes the ratio directly: 1.0 means no overshoot, lower values bounce more.

  • Small controls (toggles, checkboxes): stiffness around 400, damping near critical. Quick and calm.
  • Rewards and landings (likes, confetti badges): stiffness around 260, damping around 14. Noticeable bounce.
  • Large panels and sheets: stiffness around 140, damping around 20. Slower, heavier.

4. The same model in Kipluo

Kipluo's Flutter widgets run their own fixed-timestep spring integrator (a port of the web engine, so a widget moves the same in a browser and on a phone). The presets are SpringConfig.snappy (420/30), SpringConfig.bouncy (260/14) and SpringConfig.gentle (140/20), and several widgets accept a spring parameter to change them.

The free Jelly Checkbox uses the bouncy preset for its squash. Install the package with flutter pub add kipluo.

terms_checkbox.dart
import 'package:kipluo/kipluo.dart';

JellyCheckbox(
  value: accepted,
  label: 'I accept the terms',
  onChanged: (v) => setState(() => accepted = v ?? false),
)

// Widgets with a spring parameter take a SpringConfig:
MagneticSurface(
  spring: SpringConfig.gentle,
  child: FilledButton(onPressed: () {}, child: const Text('Explore')),
)

Accessibility checklist

Tick each one off as you check your build. Your ticks stay in this browser.

0 of 3 checked

Build it yourself or install it

Build it yourself when

One draggable element that springs back. SpringSimulation plus an unbounded controller is all you need.

Install Kipluo when

You want ready-made controls tuned with shared spring presets, sound and styles, matching the React versions.

Keep building