Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse a animation withe different duration in Flutter

I create an animation for a container with a rotation forward and reverse, I want the reverse animation is longer than forward animation how can I do?

import 'dart:math'as math;
import 'package:flutter/material.dart';
class AnimationPage extends StatefulWidget {
  @override
  _AnimationPageState createState() => _AnimationPageState();
}

class _AnimationPageState extends State<AnimationPage>
    with TickerProviderStateMixin {
  AnimationController animController;
  Animation<double> animation;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    animController =
        AnimationController(duration: Duration(seconds: 5), vsync: this);

        animation= Tween<double>(
          begin: 0, end: 2* math.pi,
          ).animate(animController)
          ..addListener((){
            setState((){});
          })
          ..addStatusListener((status) {
            if(status == AnimationStatus.completed){
              animController.reverse();
            } else if(status == AnimationStatus.dismissed){
              animController.forward();
            }
          });

    animController.forward();
like image 588
Robbie53 Avatar asked Jun 08 '20 13:06

Robbie53


1 Answers

Just add a reverseDuration parameter to the AnimationController like:

animController = AnimationController(
  duration: Duration(seconds: 5),
  reverseDuration: Duration(seconds: 8),
  vsync: this,
);
like image 50
Crizant Avatar answered Nov 06 '22 08:11

Crizant