Aay*_*hah 2 flutter lottie flutter-animation animationcontroller
我想在颤振中播放特定时间的洛蒂动画。我不想通过快进来播放它。就像如果我的动画包含总计90 frames那么如果我只想先播放30 frames那么我可以实现这一点吗?或者像如果我的动画总共有 2 秒但我只想播放第一秒。那么我该如何使用动画控制器或任何其他东西来做到这一点?
好吧,你可以尝试直接编辑控制器,所以你的 initState 将如下所示:
@override
void initState() {
super.initState();
_controller = AnimationController(vsync: this);
_controller.addListener(() {
print(_controller.value);
// if the full duration of the animation is 8 secs then 0.5 is 4 secs
if (_controller.value > 0.5) {
// When it gets there hold it there.
_controller.value = 0.5;
}
});
}
Run Code Online (Sandbox Code Playgroud)
然后你的lottie小部件看起来像这样:
Lottie.asset(
'asset/path.json',
controller: _controller,
onLoaded: (comp){
_controller
..duration = comp.duration
..forward();
})
Run Code Online (Sandbox Code Playgroud)
----------- 下面是之前的答案 -----------
还没有机会检查这一点,但尝试将控制器添加到动画中并在 onLoaded 上使用 animateTo 。
Lottie.asset(
'asset/path.json',
controller: _controller,
onLoaded: (comp){
_controller.animateTo(frameNumber);
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11434 次 |
| 最近记录: |