Robbie53
Robbie53

Reputation: 83

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();

Upvotes: 8

Views: 4709

Answers (1)

Crizant
Crizant

Reputation: 1661

Just add a reverseDuration parameter to the AnimationController like:

animController = AnimationController(
  duration: Duration(seconds: 5),
  reverseDuration: Duration(seconds: 8),
  vsync: this,
);

Upvotes: 16

Related Questions