Home > Enterprise >  Flutter how to know if GIF done animated without looping
Flutter how to know if GIF done animated without looping

Time:09-29

How to know if GIF done playing? I want to build another widget and call a function but after the GIF done animated once. Is there anyway to achieve this?

Scaffold(
  body: Container(
    constraints: const BoxConstraints.expand(),
    child: const Image(
      image: AssetImage(
        "images/splas_screen.GIF",
      ),
      fit: BoxFit.fill,
      
    ),
  ),
);

This is currently how I display the GIF because I still have no idea how to play the GIF only once without looping and call a function after.

CodePudding user response:

You can use the code block below

Widget build(BuildContext context) {
    return Container(
        decoration: BoxDecoration(color: Colors.white),
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        child: Center(
          child: Container(
            width: 100.0,
            height: 100.0,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(180),
                image: DecorationImage(
                  image: AssetImage('images/splas_screen.GIF'),
                  fit: BoxFit.fill,
                )),
          ),
        ));
  }

CodePudding user response:

You can use flutter_gif and set repeat property to ImageRepeat.noRepeat, like this:

GifImage(image:AssetImage("images/splas_screen.GIF"), controller: controller,repeat:ImageRepeat.noRepeat ),
  • Related