gpt4 book ai didi

flutter - 如何在 flutter 中的每次重复动画之间添加延迟

转载 作者:行者123 更新时间:2023-12-04 17:15:18 25 4
gpt4 key购买 nike

我的应用程序中有一个带有容器的 SlideTransition,它会永远重复,但我希望在每次重复后都有延迟。所以它会是这样的:Visual Representation

这是我的代码

  late final AnimationController _animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 1)
)..repeat(reverse: true); // Here there should be the 500 millisecond delay

late final Animation<Offset> _animation = Tween<Offset>(
begin: Offset.zero,
end: Offset(0, 1),
).animate(_animationController);

. . .

return Scaffold(
body: Center(
child: SlideTransition(
position: _animation,
child: Container(
height: 100,
width: 100,
color: Colors.red,
),
),
),
);



最佳答案

只需更改您想要的持续时间 => await Future.delayed(Duration(seconds: 3));我用 seconds: 3 测试它以获得更好的想法。

 late final AnimationController _animationController =
AnimationController(vsync: this, duration: const Duration(seconds: 3))
..forward();
 @override
void initState() {
super.initState();

_animationController.addListener(() async {
print(_animationController.status);

if (_animationController.isCompleted) {
await Future.delayed(Duration(seconds: 3));
_animationController.reverse();
} else if (_animationController.isDismissed) {
await Future.delayed(Duration(seconds: 3));
_animationController.forward();
}
});
}

关于flutter - 如何在 flutter 中的每次重复动画之间添加延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68807827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com