我正在尝试在 Flutter 中重新播放 Flare 动画。动画完成后不循环播放。我想要一个动画按需播放,相同的动画。
当我在动画之间切换时,只需交换字符串并调用 setState 就可以正常工作。有没有一种简单的方法可以做到这一点。
这是我目前正在做的事情。
class _FlareDemoState extends State<FlareDemo> {
String animationToPlay = 'activate';
@override
Widget build(BuildContext context) {
print('Animation to play: $animationToPlay');
return Scaffold(
backgroundColor: Colors.purple,
body: GestureDetector(
onTap: () {
setState(() {
});
},
child: FlareActor('assets/button-animation.flr',
animation: animationToPlay)));
}
}
当我点击动画时,我的日志结果
I/flutter (18959): Animation to play: activate
I/flutter (18959): Animation to play: activate
I/chatty (18959): uid=10088(com.example.flare_tutorial) Thread-2 identical 2 lines
I/flutter (18959): Animation to play: activate
I/flutter (18959): Animation to play: activate
I/chatty (18959): uid=10088(com.example.flare_tutorial) Thread-2 identical 7 lines
I/flutter (18959): Animation to play: activate
I/flutter (18959): Animation to play: activate
Reloaded 2 of 495 libraries in 672ms.
I/flutter (18959): Animation to play: activate
一切都被调用,它第一次播放,但之后动画不会重播。