Giu*_*che 4 animation dart flutter
我的应用程序中有一个带有容器的 SlideTransition,它会永远重复,但我希望每次重复后有一个延迟。所以它会是这样的:
这是我的代码
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);
Run Code Online (Sandbox Code Playgroud)
return Scaffold(
body: Center(
child: SlideTransition(
position: _animation,
child: Container(
height: 100,
width: 100,
color: Colors.red,
),
),
),
);
Run Code Online (Sandbox Code Playgroud)
只需更改您想要的持续时间=> await Future.delayed(Duration(seconds: 3));
我对其进行测试seconds: 3以获得更好的想法。
late final AnimationController _animationController =
AnimationController(vsync: this, duration: const Duration(seconds: 3))
..forward();
Run Code Online (Sandbox Code Playgroud)
@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();
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1753 次 |
| 最近记录: |