如何在 flutter 中配置动画控制器
how to dispose animation controller in flutter
我有一个问题,比如在处理我的控制器之前,我需要打电话给_controller.stop();
我的代码:-
AnimationController _controller;
@override
void initState()
{
super.initState();
_controller = AnimationController(duration: const Duration(milliseconds: 700), vsync: this);
_controller.repeat(reverse: true);
_controller.forward();
}
这个动画是为了展示一颗心,就像我们在 Instagram 上点赞一样,然后心会变大变小。
点击心型按钮的代码:-
onTap: ()=>controlUserLikePost(),
功能:-
controlUserLikePost()
{
_controller.reset();
_controller.forward();
}
所以,我的问题:-
@override
void dispose()
{
_controller.stop();//do i need to call it as well?
_controller.dispose();
super.dispose();// and does it matter if i dispose the controller before this line or after this line.
}
你不必在处理它之前停止它,除非你想在某个点停止动画。但关于安全处置,只需使用 _controller.dispose()
.
但是,它必须在 super.dispose()
之前,而不是之后,这很重要。
我有一个问题,比如在处理我的控制器之前,我需要打电话给_controller.stop();
我的代码:-
AnimationController _controller;
@override
void initState()
{
super.initState();
_controller = AnimationController(duration: const Duration(milliseconds: 700), vsync: this);
_controller.repeat(reverse: true);
_controller.forward();
}
这个动画是为了展示一颗心,就像我们在 Instagram 上点赞一样,然后心会变大变小。
点击心型按钮的代码:-
onTap: ()=>controlUserLikePost(),
功能:-
controlUserLikePost()
{
_controller.reset();
_controller.forward();
}
所以,我的问题:-
@override
void dispose()
{
_controller.stop();//do i need to call it as well?
_controller.dispose();
super.dispose();// and does it matter if i dispose the controller before this line or after this line.
}
你不必在处理它之前停止它,除非你想在某个点停止动画。但关于安全处置,只需使用 _controller.dispose()
.
但是,它必须在 super.dispose()
之前,而不是之后,这很重要。