2

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

4

1 回答 1

1

好的,您可以尝试直接编辑控制器,因此您的 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 小部件看起来像这样:

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

-----------下面的上一个答案-----------

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

 Lottie.asset( 
  'asset/path.json', 
   controller: _controller, 
   onLoaded: (comp){
      _controller.animateTo(frameNumber); 
})
于 2021-06-09T14:30:52.240 回答