sprung 3.0.1 copy "sprung: ^3.0.1" to clipboard
sprung: ^3.0.1 copied to clipboard

Spring curves for Flutter animations. Based on real physics equations with three damping curves.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:sprung/sprung.dart';

void main() => runApp(SprungDemoApp());

class SprungDemoApp extends StatefulWidget {
  static final title = 'Sprung';

  @override
  _SprungDemoAppState createState() => _SprungDemoAppState();
}

class _SprungDemoAppState extends State<SprungDemoApp> {
  bool toggle = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: SprungDemoApp.title,
      theme: ThemeData(primarySwatch: Colors.pink),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        /// App bar
        appBar: AppBar(
          title: Text(SprungDemoApp.title),
        ),
        body: Material(
          /// Use [Sprung] in place of any curve.
          ///
          /// Opinionated curves are [Sprung.underDamped], [Sprung.criticallyDamped], [Sprung.overDamped].
          /// This is the most common way to use [Sprung].
          ///
          /// If you wish to fine tune the damping action, use `Sprung()` which defaults to `Sprung(20)` and
          /// is the same as [Sprung.criticallyDamped]. Changing the value will fine tune the damping action.
          ///
          /// If you want full control over making custom spring curves, [Sprung.custom] allows you to adjust
          /// damping, stiffness, mass, and velocity.
          ///
          /// ```
          /// Sprung.custom(
          ///   damping: 20,
          ///   stiffness: 180,
          ///   mass: 1.0,
          ///   velocity: 0.0,
          /// )
          /// ```
          child: AnimatedContainer(
            curve: Sprung.underDamped,
            duration: Duration(milliseconds: 750),
            alignment: toggle ? Alignment.topCenter : Alignment.bottomCenter,
            margin: EdgeInsets.symmetric(vertical: 50),
            child: ElevatedButton(
              child: Text('Tap me!'),
              onPressed: () => setState(() => toggle = !toggle),
            ),
          ),
        ),
      ),
    );
  }
}
217
likes
140
pub points
93%
popularity

Publisher

verified publisherlukepighetti.com

Spring curves for Flutter animations. Based on real physics equations with three damping curves.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on sprung