An easy way to use AnimationController with Curve.

Overview

CurvedAnimationController

An easy way to use AnimationController with Curve.

Getting Started

Add dependency in your flutter project.

$ flutter pub add curved_animation_controller

or

dependencies:
  curved_animation_controller: ^1.1.0+1

or

dependencies:
  curved_animation_controller:
    git: https://github.com/salkuadrat/curved_animation_controller.git

Then run flutter pub get.

Example

There is a nice example project in the example folder. Check it out to learn how to use Curved Animation Controller.

Usage

Here is a snippet of code we usually use when we want to do some animation with curve.

AnimationController _controller = AnimationController(
  vsync: this, 
  duration: Duration(milliseconds: 300),
);

Animation _animation = Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
  parent: _controller, curve: Curves.easeInOut,
));

_controller.addListener(() => setState(() {}));

...

// start animation
_animation.forward();

...

// apply animation
Opacity(
  opacity: _animation.value,
  child: child,
)

Using CurvedAnimationController, we can apply animation with a more straightforward code:

CurvedAnimationController _animation = CurvedAnimationController(
  vsync: this, duration: Duration(milliseconds: 300),
  curve: Curves.easeInOut,
);

_animation.addListener(() => setState(() {}));

...

// start animation
_animation.start();

...

// apply animation
Opacity(
  opacity: _animation.value,
  child: child,
)

We can also use custom Tween:

CurvedAnimationController<Color> _animation = CurvedAnimationController<Color>.tween(
  ColorTween(begin: Colors.pink, end: Colors.teal),
  Duration(milliseconds: 300),
  curve: Curves.easeInCubic,
  vsync: this,
);

_animation.addListener(() => setState(() {}));

...

// start animation
_animation.forward();

...

// apply animation
Container(
  color: _animation.value,
  child: child,
)

Don't forget to dispose the controller properly:

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

Available Constructors

CurvedAnimationController(
  begin: begin,
  end: end,
  vsync: vsync,
  curve: curve,
  duration: duration,
  reverseCurve: reverseCurve,
  reverseDuration: reverseDuration,
  animationBehavior: animationBehavior,
  debugLabel: debugLabel,
);
CurvedAnimationController.tween(
  tween, // ex: ColorTween(begin: Colors.pink, end: Colors.teal)
  duration,
  vsync: vsync,
  curve: curve,
  reverseCurve: reverseCurve,
  reverseDuration: reverseDuration,
  animationBehavior: animationBehavior,
  debugLabel: debugLabel,
);
CurvedAnimationController.sequence(
  sequence, // list of sequence (List<SequenceItem>)
  duration,
  vsync: vsync,
  curve: curve,
  reverseCurve: reverseCurve,
  reverseDuration: reverseDuration,
  animationBehavior: animationBehavior,
  debugLabel: debugLabel,
);
CurvedAnimationController.tweenSequence(
  sequence, // TweenSequence
  duration,
  vsync: vsync,
  curve: curve,
  reverseCurve: reverseCurve,
  reverseDuration: reverseDuration,
  animationBehavior: animationBehavior,
  debugLabel: debugLabel,
);

Available Methods

Start animation:

start()

or :

forward()

Start animation in reverse direction:

reverse()

Stop animation:

stop()

Start animation with fling effect:

fling()

Animate to specific target value:

animateTo()

Animate back to specific target value:

animateBack()

Reset animation:

reset()

Dispose animation controller:

dispose()

Add animation listener:

addListener()

Remove animation listener:

removeListener()

Add AnimationState listener:

addStateListener()

Remove AnimationState listener:

removeStateListener()

Notify all listeners:

notifyListeners()
You might also like...

A beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.

A beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.

Motion Tab Bar A beautiful animated widget for your Flutter apps Preview: | | Getting Started Add the plugin: dependencies: motion_tab_bar: ^0.1.5 B

Nov 15, 2022

This repository demonstrates use of various widgets in flutter and tricks to create beautiful UI elements in flutter for Android and IOS

This repository demonstrates use of various widgets in flutter and tricks to create beautiful UI elements in flutter for Android and IOS

AwesomeFlutterUI The purpose of this repository is to demonstrate the use of different widgets and tricks in flutter and how to use them in your proje

Nov 13, 2022

A collection of Screens and attractive UIs built with Flutter ready to be used in your applications. No external libraries are used. Just download, add to your project and use.

A collection of Screens and attractive UIs built with Flutter ready to be used in your applications. No external libraries are used. Just download, add to your project and use.

Flutter Screens A collection of Login Screens, Buttons, Loaders and Widgets with attractive UIs, built with Flutter, ready to be used in your applicat

Dec 31, 2022

Create powerful animations in Flutter and use the hero animation for complex animations

Create powerful animations in Flutter and use the hero animation for complex animations

Hero Animation - Locations UI - Flutter Create powerful animations in Flutter and use the hero animation for complex animations. ⚡  Social Media  Twit

Dec 11, 2021

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.

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

Dec 20, 2022

The EasyRichText widget provides an easy way to use RichText.

The EasyRichText widget provides an easy way to use RichText.

easy_rich_text The EasyRichText widget makes the RichText widget easy. You do not have to split the string manually. This widget use regular expressio

Jan 4, 2023

An easy way to use pull-to-refresh.

An easy way to use pull-to-refresh.

MJRefresh An easy way to use pull-to-refresh 📜 ✍🏻Release Notes: more details Contents New Features Dynamic i18n Switching SPM Supported Swift Chaini

Dec 29, 2022

A package that gives us a modern way to show animated border as a placeholder while loading our widget with easy customization and ready to use.

A package that gives us a modern way to show animated border as a placeholder while loading our widget with easy customization and ready to use.

A package that gives us a modern way to show animated border as a placeholder while loading our widget with easy customization and ready to use.

Oct 3, 2022

Flutter RxDart Explained - The Flutter Way Flutter RxDart Explained - The Flutter Way

rx_demo A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Oct 13, 2021

The easiest way to create your animated splash screen in a fully customizable way.

The easiest way to create your animated splash screen in a fully customizable way.

Animated Splash Screen Check it out at Pub.Dev Do it your way Assets image Custom Widget Url image IconData Or just change PageTransition and/or Splas

Nov 10, 2022

A flutter widget to indicate loading progress. Easy to use, easy to extend

💙 👾 💫 A flutter widget to indicate loading progress. Easy to use, easy to extend

May 30, 2022

A TabBarController that is easy to use for flutter developers. 🥰 It supports various styles of page navigation, and you can also use it to customize your favorite styles. 🍻🍻

A TabBarController that is easy to use for flutter developers. 🥰 It supports various styles of page navigation, and you can also use it to customize your favorite styles. 🍻🍻

easy_tab_controller A user-friendly TabBarController widget for flutter developer. Getting Started This project is a starting point for a Flutter plug

May 26, 2022

Easy to use Animated Maps Markers with a detail card. Use it for a store or any place locator.

interactive_maps_marker for Flutter Easy to use Animated Maps Markers with detail card. Use it for store or any place locator. Demo Usage Add this pac

Dec 28, 2022

A simple Todo app designed to simply use GraphQL as backend and provide an easy to use UI/UX.

A simple Todo app designed to simply use GraphQL as backend and provide an easy to use UI/UX.

simple_todo_app A simple Todo app designed to simply use GraphQL as backend and provide an easy to use UI/UX. A breakdown of the project and explanati

Oct 9, 2022

Inner Drawer is an easy way to create an internal side section (left/right) where you can insert a list-menu or other.

Inner Drawer is an easy way to create an internal side section (left/right) where you can insert a list-menu or other.

flutter_inner_drawer Inner Drawer is an easy way to create an internal side section (left/right) where you can insert a list menu or other. Installing

Dec 30, 2022

A package provides an easy way to add shimmer effect in Flutter project

A package provides an easy way to add shimmer effect in Flutter project

Shimmer A package provides an easy way to add shimmer effect in Flutter project How to use import 'package:shimmer/shimmer.dart'; SizedBox( width:

Jan 8, 2023

This is not an app. I made this architecture to build robust and easy-to-maintain products but in a faster way.

simple_architecture_flutter This is not an app. I made this architecture to build robust and easy-to-maintain products but in a faster way. Info I use

Oct 28, 2022

Donating made easy, the kifu. way

Donating made easy, the kifu. way

Donating made easy, the kifu. way An entry for HackNITR 3.0 Installation Refer to DEPLOY instructions The Problem While brainstorming for a project id

Nov 15, 2021
Comments
  • Controller not animating to right target

    Controller not animating to right target

    Hello, it seems like the CurvedAnimationController won't animate to the right target.

    My constructor:

    CurvedAnimationController(
          curve: Curves.easeInOutQuart,
          vsync: this,
          duration: Duration(seconds: 1),
    )
    

    As you can see in the console output, even if animateTo(0.6) is called, which should animate to that target. The controller animates to about 0.84.

    flutter: curvedAnimationController.value: 1.0
    
    flutter: animateTo: 0.6
    flutter: curvedAnimationController.value: 1.0
    flutter: curvedAnimationController.value: 0.9973060470074415
    flutter: curvedAnimationController.value: 0.9958655436057597
    flutter: curvedAnimationController.value: 0.9916553031653166
    flutter: curvedAnimationController.value: 0.9858636856079102
    flutter: curvedAnimationController.value: 0.9732524156570435
    flutter: curvedAnimationController.value: 0.9678608030080795
    flutter: curvedAnimationController.value: 0.946941701695323
    flutter: curvedAnimationController.value: 0.9374455213546753
    flutter: curvedAnimationController.value: 0.9164605587720871
    flutter: curvedAnimationController.value: 0.9041157960891724
    flutter: curvedAnimationController.value: 0.8733493089675903
    flutter: curvedAnimationController.value: 0.8393326997756958
    
    flutter: animateTo: 1.0
    flutter: curvedAnimationController.value: 0.8393326997756958
    flutter: curvedAnimationController.value: 0.9264676123857498
    flutter: curvedAnimationController.value: 0.9359242767095566
    flutter: curvedAnimationController.value: 0.9667282104492188
    flutter: curvedAnimationController.value: 0.9817894846200943
    flutter: curvedAnimationController.value: 0.9936141967773438
    flutter: curvedAnimationController.value: 0.99713134765625
    flutter: curvedAnimationController.value: 0.999182315543294
    flutter: curvedAnimationController.value: 1.0
    
    opened by jonaspoxleitner 0
Flexible and easy to use page transitions.

flutter_villains What are heroes without villains? (Profile image from: https://unsplash.com/photos/pAs4IM6OGWI) Check out the article. What are villa

Norbert Kozsir 356 Dec 12, 2022
✨A clean and lightweight loading/toast widget for Flutter, easy to use without context, support iOS、Android and Web

Flutter EasyLoading English | 简体中文 Live Preview ?? https://nslog11.github.io/flutter_easyloading Installing Add this to your package's pubspec.yaml fi

nslog11 1k Jan 9, 2023
A customizable and easy to use UI widgets to help develop apps faster

Lenore UI Beautiful, customizable and easy to use UI widgets to help me (or maybe you) develop my (or maybe your) apps faster. This is my personal pac

Lenore 3 Nov 4, 2022
Easy to use, customizable and pluggable Theme Provider.

theme_provider Easy to use, customizable Theme Provider. This provides app color schemes throughout the app and automatically rebuilds the UI dynamica

K.D. Sunera Avinash Chandrasiri 143 Dec 10, 2022
An animation Framework for Flutter. It is state-based, declarative, extensible, composable and easy to use.

⚠️ This package is in an early state of development. If you find any bugs or have any suggestions, please open an issue. Fleet is an animation framewo

Gabriel Terwesten 3 Sep 29, 2022
Help you to build pull-down refresh and pull-up loading in the simplest way.

frefresh Help you to build pull-down refresh and pull-up loading in the simplest way. Although unprecedented simplicity, but the effect is amazing. It

Fliggy Mobile 427 Nov 26, 2022
🔥🔥🔥 Easy to build an animation set

✨ Flutter Animation Set [Lanuage ~~] English | 中文文档 Simplified Flutter stagger animation.To drive the Flutter stagger animation through a timeline in

YYDev 271 Oct 31, 2022
🔥🔥🔥 Easy to build an animation set

✨ Flutter Animation Set [Lanuage ~~] English | 中文文档 Simplified Flutter stagger animation.To drive the Flutter stagger animation through a timeline in

YYDev 271 Oct 31, 2022
IntroAnimationSlider - A simple Flutte Animation Introduction for Mobile app easy to implement Using intro Views flutter

introappanimation simple Flutte Animation Introduction for Mobile app easy to im

null 3 Sep 22, 2022
Simple to use yet powerfull style widgets with syntax inspired by CSS.

Division Simple to use yet powerfull style widgets with syntax inspired by CSS. Please check out styled_widget which is a replacement of Division! The

Rein Gundersen Bentdal 266 Nov 20, 2022