如何在颤动中的AnimationController.Repeat()之间添加一些延迟 [英] How to add some delay between AnimationController.repeat() in Flutter
本文介绍了如何在颤动中的AnimationController.Repeat()之间添加一些延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试通过将值传递给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);
}
});
我还尝试在动画中添加补间。这也帮不上忙。你能帮我弄清楚我哪里出错了吗?
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,它现在可以像我预期的那样工作了。您所要做的就是自己重复控制器,而不是尝试向控制器添加延迟。Repeat()
if(status == AnimationStatus.completed){
Future.delayed(Duration(milliseconds: 5000),(){
_controller.forward(from: 0.0);
});
}
这篇关于如何在颤动中的AnimationController.Repeat()之间添加一些延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文