如何在颤振中播放特定持续时间的乐天动画

我想在颤动中播放特定持续时间的乐透动画。我不想通过快进来播放它。比如如果我的动画总共包含 90 frames 那么如果我只想先播放 30 frames 那么我可以做到这一点吗?或者,如果我的动画总共有 2 秒,但我只想播放第一秒。那么我如何使用动画控制器或其他任何东西来做到这一点?

Doris9900 回答:如何在颤振中播放特定持续时间的乐天动画

好的,您可以尝试直接编辑控制器,因此您的 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;
      }
    });
  }

然后您的彩票小部件如下所示:

  Lottie.asset( 
      'asset/path.json',controller: _controller,onLoaded: (comp){
          _controller
          ..duration = comp.duration
          ..forward(); 
    })

----------- 以前的答案 -----------

还没有机会检查这一点,但尝试将控制器添加到您的动画中并在 onLoaded 上使用 animateTo。

 Lottie.asset( 
  'asset/path.json',onLoaded: (comp){
      _controller.animateTo(frameNumber); 
})
本文链接:https://www.f2er.com/283755.html

大家都在问