dart 如何玩半乐天动画?

ruarlubt  于 2023-02-20  发布在  其他
关注(0)|答案(1)|浏览(84)

帮帮我!我想静音和取消静音按钮与洛蒂动画。但这个mute.json的json动画都有。所以我需要一个点击播放洛蒂半动画这样。当点击x1c 0d1x和

@override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this)
      ..value = 0.5
      ..addListener(() {
        setState(() {
          // Rebuild the widget at each frame to update the "progress" label.
        });
      }); 
  }



     Column(
          children[
                   Lottie.asset( 
                                  controller: _controller,
                                  'assets/mute.json', 
                                  animate: true,
                                  onLoaded: (composition) {
                                       setState(() { 
                                      _controller.duration = composition.duration;
                                    });
                                  },
                                ),
],
),
gtlvzcf8

gtlvzcf81#

bool mute = false;

@override
  void initState() {
    super.initState();
                                                  // add duration
    _controller =  AnimationController(vsync: this, duration: Duration(milliseconds: 300));

  }

在控制器上使用animateTo方法。

InkWell(
            onTap: () {
              mute = !mute;
              log(mute.toString());
              if (mute) {
                _controller.animateTo(0.5);
              } else {
                _controller.animateTo(0);
              }
            },
            child: LottieBuilder.network(
              "https://maxst.icons8.com/vue-static/landings/animated-icons/icons/no-sound/no-sound.json",
              controller: _controller,
              height: 200,
            ),
          ),

相关问题