springster 0.4.0+1 copy "springster: ^0.4.0+1" to clipboard
springster: ^0.4.0+1 copied to clipboard

Spring animations and simulations, simplified.

Springster #

Pub Version Coverage lintervention_badge Bluesky

Spring animations and simulations, simplified.

Features 🎯 #

  • 🎨 Simple spring-based animations with customizable bounce and duration
  • 🔄 Spring-based draggable widgets with smooth return animations
  • 🎯 Spring curves for use with standard Flutter animations
  • 📱 2D spring animations for complex movements

Try it out #

Open Example

Installation 💻 #

❗ In order to start using Springster you must have the Dart SDK installed on your machine.

Add to your pubspec.yaml:

dependencies:
  springster: ^latest_version
copied to clipboard

Or install via dart pub:

dart pub add springster
copied to clipboard

Usage 💡 #

Simple Spring Animation #

Use SpringBuilder for basic spring animations:

1D Hover example gif

SpringBuilder(
  spring: Spring.bouncy,
  value: targetValue, // Changes trigger smooth spring animation
  builder: (context, value, child) {
    return Container(
      width: value,
      height: value,
      color: Colors.blue,
    );
  },
)
copied to clipboard

If you want a simple two-dimensional spring animation, you can use SpringBuilder2D:

2D Redirection example gif

SpringBuilder2D(
  spring: Spring.bouncy,
  value: (100, 100), // Changes trigger smooth spring animation and redirect dynamically
  builder: (context, value, child) {
    return Transform.translate(
      offset: Offset(value.x, value.y),
      child: child,
    );
  },
  child: Container(
    width: 100,
    height: 100,
    color: Colors.blue,
  ),
)
copied to clipboard

Spring Draggable #

springster comes with a SpringDraggable widget that allows you to drag a widget around the screen with a spring return animation. It works just like the Draggable widget in Flutter and supports native Flutter DragTargets, however it comes with a few sensible defaults and extra features.

Spring Draggable example gif

SpringDraggable(
  spring: Spring.bouncy,
  child: Container(
    width: 100,
    height: 100,
    color: Colors.blue,
  ),
  data: 'my-draggable-data',
)
copied to clipboard

Low-level Spring Simulation #

If you need more control over the spring simulation, you can use the SpringSimulationController and SpringSimulationController2D classes.

final controller = SpringSimulationController(
  spring: Spring.bouncy,
  vsync: this,
);
copied to clipboard

They work similarly to the AnimationController class in Flutter and allow you to drive the spring simulation with a target value, while maintaining velocity between target changes.

Predefined Springs 🎯 #

Springster comes with several predefined spring configurations:

  • const Spring() - Smooth spring with no bounce
  • Spring.instant - An effectively instant spring
  • Spring.defaultIOS - iOS-style smooth spring with no bounce
  • Spring.bouncy - Spring with higher bounce
  • Spring.snappy - Snappy spring with small bounce
  • Spring.interactive - Lower response spring for interactive animations

You can also create custom springs:

const mySpring = Spring(
  duration: 0.5, // Settling duration
  bounce: 0.2,   // Bounce amount (-1 to 1)
);

// Or using damping fraction
const mySpring = Spring.withDamping(
  dampingFraction: 0.7,
  duration: 0.5,
);
copied to clipboard

Acknowledgements #

Springster was partially adapted from and heavily inspired by fluid_animations.

47
likes
150
points
684
downloads

Publisher

verified publisherwhynotmake.it

Weekly Downloads

2024.09.13 - 2025.03.28

Spring animations and simulations, simplified.

Homepage
Repository (GitHub)

Topics

#spring #animation #physics

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on springster