flutter - 如何在 Flutter 中反转具有不同持续时间的动画

标签 flutter animation

我为容器创建了一个向前和向后旋转的动画,我希望反向动画比正向动画长,我该怎么办?

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

最佳答案

只需添加一个 reverseDuration AnimationController 的参数喜欢:

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

关于flutter - 如何在 Flutter 中反转具有不同持续时间的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62263790/

相关文章:

android - Flutter Base64编码字符串不完整

android - Viewflipper 动画在第一次滑动时不起作用

javascript - GreenSock 动画未按预期工作

javascript - 暂停移相器动画

flutter - 如何在 Flutter/Dart 中按日期时间对列表中的项目进行排序?

flutter - 如何测试Flutter中流有延迟的StreamBuilder?

dart - 如何在 Flutter/dart 中获取星期几的日期?

flutter - dart 中的 .. 运算符是什么?

Jquery 倒计时平滑动画

java - 随时间改变颜色的 RGB 值