Yashraj
Yashraj

Reputation: 999

How to play .gif for some seconds?

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,
  )
])

I want play GIF file for 1 or 2 seconds then I have to show png file.

How can I achieve it?

Upvotes: 0

Views: 903

Answers (1)

u0j
u0j

Reputation: 172

You can, this solution is simple :

Add new variable in top class var show = false;

after that's add this function :

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

Now add this your code

    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,
        )
     ])

Upvotes: 2

Related Questions