Animation package for Flutter, inspired by Animate.css

Related tags

Animation animator
Overview

animator

Enables you to create stunning flutter animations, faster, efficient and with less code.

Null safety:

For null safety please use flutter_animator: ^3.1.0, without null safety: flutter_animator: 2.1.0

Partly inspired by the amazing Animate.css package by Dan Eden. Please note, although it's inspired by Animate.css, this still is a Flutter package, meaning it will be available for all flutter-supported platforms.

Features:

  • Combine and chain Tweens with multiple easing-curves.
  • Less boilerplate code by using a widget which directly handles the controller, animations etc.
  • Automatically (re)starts animations on hot-reload after saving.
  • Animate your project with ease using the Animate.css based Widgets.

Please press the like button if you like this package, or star it on github.

Getting Started

Note: To see all of the animated widgets in action be sure to run the app in the demo_app package, or view them on the Animate.css page.

Put the dependency inside your pubspec.yml and run packages get.

Using one of the Animate.css style widgets:

import 'package:flutter/widgets.dart';
import 'package:flutter_animator/flutter_animator.dart';

class TestAnimatedWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RubberBand(
      child: Text(
        'Rubber',
        style: TextStyle(fontSize: 20),
      ),
    );
  }
}

Please note that you can use the magnitude property in the AnimationPreferences to control the magnitude of the animations.

Using a GlobalKey to enable play/stop/reverse animations from code:

import 'package:flutter/widgets.dart';
import 'package:flutter_animator/flutter_animator.dart';

class TestAnimatedWidget extends StatefulWidget {
  @override
  _TestAnimatedWidgetState createState() => _TestAnimatedWidgetState();
}
class _TestAnimatedWidgetState extends State<TestAnimatedWidget> {
  //Register a key in your state:
  GlobalKey<AnimatorWidgetState> _key = GlobalKey<AnimatorWidgetState>();
  
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
            //Render the widget using the _key
            child: RubberBand(
              key: _key,
              child: Text(
                'Rubber',
                style: TextStyle(fontSize: 60),
              ),
            ),
        ),
        Padding(
            padding: EdgeInsets.fromLTRB(10, 10, 10, 30),
            child: IconButton(
              icon: Icon(
                Icons.play_arrow,
                color: Colors.green,
              ),
              //Use _key.currentState to forward/stop/reverse
              onPressed: () => _key.currentState.forward(),
            ),
        ),
      ],
    );
  }
}

Create your own:

Below is the code (with extra comments) from the actual FadeInDown animated widget. It should give you a clear insight on how to animate with the Animator using the AnimatorWidget.

import 'package:flutter/widgets.dart';

import '../../flutter_animator.dart';

///Firstly, we create an _AnimationDefinition_.
///This is the actual animation part, which gets driven by the _AnimatorWidget_.
class FadeInDownAnimation extends AnimationDefinition {
  FadeInDownAnimation({
  ///[AnimationPreferences] allows us to use the animation with different parameters for:
  ///offset, duration, autoPlay and an animationStatusListener.
    AnimationPreferences preferences = const AnimationPreferences(),
  }) : super(
          preferences: preferences,
          ///If you want to use the size of the widget, you need to define it here. (needsScreenSize is also available)
          needsWidgetSize: true,
          ///The opacity to use on the first render when using screenSize or widgetSize.
          ///In some cases 'flickering' may appear when this isn't set to 1.0 or 0.0 respectively.
          preRenderOpacity: 0.0,
        );

  ///Use the build function to actually render the animated values.
  ///Performance-wise it's better to use a FadeTransition for opacity animation.
  ///Use AnimatedBuilder to update te animation and it's values.
  @override
  Widget build(BuildContext context, Animator animator, Widget child) {
    return FadeTransition(
      ///Use animator.get([KEY]) to get to the Animation object.
      opacity: animator.get("opacity"),
      child: AnimatedBuilder(
        ///[Animator] exposes the AnimationController via animator.controller.
        animation: animator.controller,
        child: child,
        builder: (BuildContext context, Widget child) => Transform.translate(
          child: child,
          ///Use animator.get([KEY]).value to get the animated value.
          offset: Offset(0.0, animator.get("translateY").value),
        ),
      ),
    );
  }

  ///Inside the getDefinition method we return the actual animation.
  @override
  Map<String, TweenList> getDefinition({Size screenSize, Size widgetSize}) {
    return {
      ///Define a [KEY] and a list of Animated values from 0 to 100 percent.
      ///Please not that you can also define an animation curve inside the [TweenPercentage] class:
      ///TweenPercentage(percent: 0, value: 0.0, curve: Curves.ease),
      "opacity": TweenList<double>(
        [
          TweenPercentage(percent: 0, value: 0.0),
          TweenPercentage(percent: 100, value: 1.0),
        ],
      ),
      "translateY": TweenList<double>(
        [
          TweenPercentage(percent: 0, value: -widgetSize.height),
          TweenPercentage(percent: 100, value: 0.0),
        ],
      ),
    };
  }
}

///To use the AnimationDefinition we just created we could do the following:
///For a single animation:
/// AnimatorWidget(child: [child], definition: FadeInDownAnimation());
/// 
///For In & Out Animations:
///  InOutAnimation(child: [child), inDefinition: FadeInDownAnimation(), outDefinition: ...);
/// 

Available default animations:

Attention Seekers

Attention Seekers

  • Bounce
  • Flash
  • HeadShake
  • HeartBeat
  • Jello
  • Pulse
  • RubberBand
  • Shake
  • Swing
  • Tada
  • Wobble

Bouncing Entrances

Bouncing Entrances

  • BounceIn
  • BounceInDown
  • BounceInLeft
  • BounceInRight
  • BounceInUp

Bouncing Exits

Bouncing Exits

  • BounceOut
  • BounceOutDown
  • BounceOutLeft
  • BounceOutRight
  • BounceOutUp

Fading Entrances

Fading Entrances

  • FadeIn
  • FadeInDown
  • FadeInDownBig
  • FadeInLeft
  • FadeInLeftBig
  • FadeInRight
  • FadeInRightBig
  • FadeInUp
  • FadeInUpBig

Fading Exits

Fading Exits

  • FadeOut
  • FadeOutDown
  • FadeOutDownBig
  • FadeOutLeft
  • FadeOutLeftBig
  • FadeOutRight
  • FadeOutRightBig
  • FadeOutUp
  • FadeOutUpBig

Flippers

Flippers

  • Flip
  • FlipInX
  • FlipInY
  • FlipOutX
  • FlipOutY

Lightspeed

Lightspeed

  • LightSpeedIn
  • LightSpeedOut

Rotating Entrances

Rotating Entrances

  • RotateIn
  • RotateInDownLeft
  • RotateInDownRight
  • RotateInUpLeft
  • RotateInUpRight

Rotating Exits

Rotating Exits

  • RotateOut
  • RotateOutDownLeft
  • RotateOutDownRight
  • RotateOutUpLeft
  • RotateOutUpRight

Sliding Entrances

Sliding Entrances

  • SlideInDown
  • SlideInLeft
  • SlideInRight
  • SlideInUp

Sliding Exits

Sliding Exits

  • SlideOutDown
  • SlideOutLeft
  • SlideOutRight
  • SlideOutUp

Slit Entrances

Sliding Entrances

  • SlitInDiagonal
  • SlitInHorizontal
  • SlitInVertical

Slit Exits

Sliding Exits

  • SlitOutDiagonal
  • SlitOutHorizontal
  • SlitOutVertical

Specials

Specials

  • CrossFadeAB (*not in preview)
  • Hinge
  • JackInTheBox
  • RollIn
  • RollOut

Zooming Entrances

Zooming Entrances

  • ZoomIn
  • ZoomInDown
  • ZoomInLeft
  • ZoomInRight
  • ZoomInUp

Zooming Exits

Zooming Exits

  • ZoomOut
  • ZoomOutDown
  • ZoomOutLeft
  • ZoomOutRight
  • ZoomOutUp
Comments
  • feat: flutter 3 support

    feat: flutter 3 support

    ../../.pub-cache/hosted/pub.flutter-io.cn/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:105:22: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
     - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../fvm/versions/3.0.0/packages/flutter/lib/src/widgets/binding.dart').
          WidgetsBinding.instance!.addPostFrameCallback((_) {
                         ^
    
    opened by Adherentman 3
  • Animator not working on Web?

    Animator not working on Web?

    in top of class:
      final GlobalKey<AnimatorWidgetState> inOutAnimation = GlobalKey<AnimatorWidgetState>();
    
    ...And the wiget:
    FadeInLeft(
                      key: inOutAnimation,
                      preferences: AnimationPreferences(
                        autoPlay: AnimationPlayStates.None,
                      ),
                      child: Container(
                        height: Get.height*.15,
                        color: ThemeUtils.darkGrey.withOpacity(.3),
                        child: topMenu(),
                      ),
                    ),
    

    Getting error: Expected a value of type 'Animation', but got one of type '_AnimatedEvaluation<double?>'

    opened by ervindobri 3
  • support for Flutter 3

    support for Flutter 3

    ../../.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.1/lib/widgets/animator_widget.dart:102:22: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
     - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
          WidgetsBinding.instance!.addPostFrameCallback((_) {
    

    build is breaking because of this lib

    opened by daadu 2
  • AnimationPreferences bug with autoPlay PingPong

    AnimationPreferences bug with autoPlay PingPong

    I have set AnimationPreferences

    RollIn(
      child: Image.asset(
        "assets/asset.png",
      ),
      preferences: AnimationPreferences(
        autoPlay: AnimationPlayStates.PingPong,
      ),
    ),
    

    AnimationPlayStates.Loop and AnimationPlayStates.PingPong behave exactly the same. There is no forward and reverse behaviour for PingPong

    opened by alexgtn 2
  • fix null safety bugs

    fix null safety bugs

    current nullsafety version not work correctly i face some issuse with like

    type '_AnimatedEvaluation<double?>' is not a subtype of type 'Animation<double>' in type cast
    When the exception was thrown, this was the stack:
    #0      FadeOutAnimation.build (package:flutter_animator/widgets/fading_exits/fade_out.dart:40:40)
    

    this from offical example after migrate it

    also this

    RubberBand(
                child: FlatButton(onPressed: () {}, child: Text("hii")),
              )
    

    will throw

    type 'Matrix4' is not a subtype of type 'num'
    The relevant error-causing widget was:
      AnimatedBuilder
      /flutter_animator-3.1.0/lib/widgets/attention_seekers/rubber_band.dart:39:12
    
    

    ( the bugs here that type here is Matrix4? not Matrix4 so the if(T == Matrix4) give false )


    every issuses here because of use " as " like " as List<double>" or 'as List<Widget>' ( "dart migrate" do this bug a log )


    this pull request solve this bugs migrate example and demo_app to null safety ( also i test both run fine now )

    opened by Ali1Ammar 2
  • Control play/stop/reverse animations without GlobalKey ?

    Control play/stop/reverse animations without GlobalKey ?

    Can I control animation play/stop/reverse without GlobaleKey ?

    I use this widget in list view, it have huge items, It seem bad pratices that use GlobaleKey here.

    opened by dodatw 1
  • how to animate widgets just once?

    how to animate widgets just once?

    I am trying to translate widget using fade in right. But i want to do this only once. While now i see that on tap of the widget the animation executes itself.

    opened by roopa1712 1
  • fix setState called after dispose issue

    fix setState called after dispose issue

    Upon hot reloading, flutter throws setState called after dispose, as setState invocation is hooked to addPostFrameCallback.

    Steps to reproduce the issue:

    1. Deploy any simple animation.
    2. Trigger hot reload.

    Solution: Check if the widget is mounted before proceeding.

    opened by rithviknishad 0
  • Chaining animations?

    Chaining animations?

    Hello, I'd like to chain to animations and create a sequence.

    InOutAnimation depends on user interaction and does not run automatically.

    Also, I am not sure that I understand how to use AnimationDefinition to achieve a chained animation.

    Could you give an example of how to combine LightSpeedIn and LightSpeedOut into one animation that runs on its own?

    This seems not to be the right approach:

    LightSpeedIn
      child: LightSpeedOut
    

    Thank you!

    opened by xErik 0
Owner
Sjoerd van Den Berg
Sjoerd van Den Berg
Convert text to paths and animate them with this Flutter package

Text to Path Maker This is a pure Flutter and Dart package that allows you to convert text--both characters and icons--into paths. It can generate SVG

Ashraff Hathibelagal 81 Sep 23, 2022
Flutter animation tutorials, such common animation, flare animation.

❤️ Star ❤️ the repo to support the project or ?? Follow Me.Thanks! Facebook Page Facebook Group QQ Group Developer Flutter Open Flutter Open 963828159

Flutter开源社区 123 Sep 3, 2022
Flutter animation tutorials, such common animation, flare animation.

❤️ Star ❤️ the repo to support the project or ?? Follow Me.Thanks! Facebook Page Facebook Group QQ Group Developer Flutter Open Flutter Open 963828159

Flutter开源社区 123 Sep 3, 2022
A collection of loading indicators animated with CSS

SpinKit Simple loading spinners animated with CSS. See demo. SpinKit only uses (transform and opacity) CSS animations to create smooth and easily cust

Tobias Ahlin 19k Dec 26, 2022
Delightful, performance-focused pure css loading animations.

Loaders.css Delightful and performance-focused pure css loading animations. What is this? See the demo A collection of loading animations written enti

Connor Atherton 10.2k Jan 2, 2023
A Flutter library that makes animation easer. It allows for separation of animation setup from the User Interface.

animator This library is an animation library for Flutter that: makes animation as simple as the simplest widget in Flutter with the help of Animator

MELLATI Fatah 225 Dec 22, 2022
A simple animated circular menu for Flutter, Adjustable radius, colors, alignment, animation curve and animation duration.

A simple animated circular menu for Flutter, Adjustable radius, colors, alignment, animation curve and animation duration. pub package Getting Started

Hasan Mohammed 91 Dec 20, 2022
Like Button is a flutter library that allows you to create a button with animation effects similar to Twitter's heart when you like something and animation effects to increase like count.

like_button Language: English | 中文简体 Like Button is a flutter library that allows you to create a button with animation effects similar to Twitter's h

FlutterCandies 357 Dec 27, 2022
BKash-Ballance-Animation - BKash Ballance Animation For Flutter

BKash-Ballance-Animation before clone the GitHub repository please give a star o

Blackshadow Software Ltd 11 Sep 1, 2022
Fisherman-Fishing-Animation - Fisherman Fishing Animation With Flutter

Fisherman Fishing Animation before clone the GitHub repository please give a sta

Blackshadow Software Ltd 9 Oct 27, 2022
Nubank card animation - Nubank card animation built with flutter

Nubank card animation Project | Technologies | How to run | How to contribute ??

Lucas da Silva Barbosa 8 Nov 6, 2022
Fade animation - Add fade animation to your app easily

fade_animation Add fade animation to your app easily using simple_animations pac

Mazouzi Aymene 3 Oct 6, 2022
✨ A collection of loading indicators animated with flutter. Heavily Inspired by http://tobiasahlin.com/spinkit.

✨ Flutter Spinkit A collection of loading indicators animated with flutter. Heavily inspired by @tobiasahlin's SpinKit. ?? Installing dependencies:

Jeremiah Ogbomo 2.7k Dec 30, 2022
Inspired by Reflectly App Made in Flutter ❤️

Inspired By Reflectly App ?? Gif ?? Screenshots Download the Following App for Preview ?? Flutter Tutorial All Flutter Tutorials plus additional Code

Sagar Shende 214 Nov 16, 2022
A light weight package for flutter apps, that easily shows a splash screen with a nice fade animation.

Animated Splash Screen Using the package Get the library environment: sdk: ">=2.1.0 <3.0.0" Add dependency in pubspec.yaml dependencies: animated_

Mohammad Fayaz 112 Oct 6, 2022
Flutter package for Skeleton Text Animation

skeleton_text A package provides an easy way to add skeleton text loading animation in Flutter project Dependency dependencies: skeleton_text: How

101Loop 35 Aug 15, 2022
A Flutter package to custom splash screen like change logo icon, logo animation, and splash screen background color.

Custom Splash Screen A Flutter package to custom splash screen: change logo icon, logo animation, and splash screen background color. (Custom from ani

tranhuycong 78 Sep 6, 2022
A flutter package which display the library collapse according to the number of images associated with hero animation

?? Gallery Collapse A flutter package which display the library collapse accordi

null 6 Sep 12, 2022
Bubbleslider - A flutter package support a slider customize UI with bubble animation

bubble_slider This package support a slider customize UI with bubble animation.

MindInventory 11 Jul 26, 2022