是否可以向StatusListener
添加某种AnimatedContainer
?我想在动画完成和开始动画时收到通知。
使用AnimatedBuilder的代码:
new AnimatedBuilder(
animation: _animation,
child: char,
builder: (BuildContext context, Widget child) {
return new Transform(
child: child,
transform: new Matrix4.translation(new vect.Vector3(-100.0, y, 0.0)),
);
},
)
_animation
和_controller
的代码:
_controller = new AnimationController(
duration: const Duration(seconds: 5),
vsync: this,
);
_animation = new CurvedAnimation(
parent: _controller,
curve: Curves.linear,
)..addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.completed)
print('completed');
});
答案 0 :(得分:0)
AnimatedContainer
只是方便动画制作。如果你想要一个听众,你应该考虑实现自己的AnimationController
看看我的回答here,举个简单的例子。您基本上创建了AnimationController
,而不是用作动画的父级(例如CurvedAnimation
)。您可以将侦听器附加到动画。
<强> ## - 编辑 - ## 强>
对您的代码示例做出反应,请尝试以下操作:
_controller = new AnimationController(
duration: const Duration(seconds: 5),
vsync: this,
)..forward();
_animation = new CurvedAnimation(
parent: _controller,
curve: Curves.linear,
)..addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.completed)
print('completed');
});
使用像这样的AnimatedBuilder:
new AnimatedBuilder(
animation: _animation,
child: new Text('a'),
builder: (BuildContext context, Widget child) {
return new Transform(
child: child,
transform: new Matrix4.translation(new Vector3(0.0, _controller.value * 10, 0.0)),
);
},
);
这对我有用;)