6

我需要在每次重复调用动画之间添加一些延迟。类似于下图的东西。 在此处输入图像描述

我试图通过将值传递给 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,
      ),
    );
4

1 回答 1

8

感谢@pskink现在它正在按我的预期工作。您所要做的就是自己重复控制器,而不是尝试向 controller.repeat() 添加延迟

if(status == AnimationStatus.completed){
 Future.delayed(Duration(milliseconds: 5000),(){
   _controller.forward(from: 0.0);
 });
}
于 2020-10-07T07:01:46.447 回答