如何在Flutter中使用不同的持续时间实现动画反转

7

我为容器创建了一个来回旋转的动画,我希望反向动画比正向动画更长,该怎么做?

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

3
请查看 Duration durationDuration reverseDuration - pskink
在 @pskink 的评论中添加位,您可以在初始化 AnimationController 时设置。 - ibhavikmakwana
1个回答

14

只需像这样向 AnimationController 添加一个reverseDuration参数:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接