如何在Flutter中的AnimationController.repeat之间增加一些延迟

问题描述

我需要在动画的每次迭代之间添加一些延迟以重复调用。如下图所示。

enter image description here

我试图通过将值传递给repeat方法的period参数来做到这一点,但这不是我期望的。

_controller = AnimationController(vsync: this,duration: widget.period)
      ..addStatusListener((AnimationStatus status) {
        if (status != AnimationStatus.completed) {
          return;
        }
        _count++;
        if (widget.loop <= 0) {
          //_controller.repeat(period: Duration(microseconds: 5000));
          _controller.repeat();
        } else if (_count < widget.loop) {
          _controller.forward(from: 0.0);
        }
      });

我还尝试过将Tween与动画一起添加。那也没有帮助。您能帮我弄清楚我出了什么问题吗?

AnimatedBuilder(
      animation: Tween<double>(begin: 0.0,end: 1.0).animate(
        CurvedAnimation(
          parent: _controller,curve: Interval(0.5,1.0)
        ),),child: widget.child,builder: (BuildContext context,Widget child) => _Shiner(
        child: child,direction: widget.direction,gradient: widget.gradient,percent: _controller.value,enabled: widget.enabled,);

解决方法

感谢@pskink现在可以正常使用了。您要做的就是自己重复控制器,而不是尝试增加controller.repeat()的延迟

if(status == AnimationStatus.completed){
 Future.delayed(Duration(milliseconds: 5000),(){
   _controller.forward(from: 0.0);
 });
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...