如何播放.gif几秒钟?

问题描述 投票:0回答:1
Stack([
Image.asset(
    "assets/Icon/Checkbox.png",
    color: uncheckedColor,
    height: 22,
    width: 22,
    ),
Image.asset(
    "assets/Icon/fullyComplete1.gif",
    color: uncheckedColor,
    scale: 2.5,
    opacity: const AlwaysStoppedAnimation<double>(1.0),
    height: 22,
    width: 22,
    gaplessPlayback: true,
  )
])

我想播放 GIF 文件 1 或 2 秒,然后我必须显示 png 文件。

我怎样才能实现它?

flutter dart animated-gif
1个回答
2
投票

可以,这个解决方案很简单:

在顶级类中添加新变量

var show = false;

之后添加这个功能:

  @override
  void initState() {
  Future.delayed(const Duration(seconds: 2), () {
         setState(() => show = true);
   });
   super.initState();
  }

现在添加您的代码

    Stack([
show ? Image.asset(
    "assets/Icon/Checkbox.png",
    color: uncheckedColor,
    height: 22,
    width: 22,
    ) :
   Image.asset(
    "assets/Icon/fullyComplete1.gif",
    color: uncheckedColor,
    scale: 2.5,
    opacity: const AlwaysStoppedAnimation<double>(1.0),
    height: 22,
    width: 22,
    gaplessPlayback: true,
        )
     ])
© www.soinside.com 2019 - 2024. All rights reserved.