Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter gif won't play again when reopening dialog

Tags:

flutter

I have a set up where I have an alert dialog with a gif in it. When the dialog opens, I want the gif to only play once, which I was able to accomplish with the top answer on this post:

How to stop GIF loop in flutter?

The problem is that the gif won't play a second time when I reopen the dialog. I'm not sure if this is a problem with the framework or the gif resource itself.

Any help would be appreciated.

EDIT: Per request by @Johnnyxsx, here's a minimal version of my code with the pertinent components.

import 'package:flutter/material.dart';
import 'package:geocash_flutter/services/size_config.dart';

class LoseDialog extends StatefulWidget {
  const LoseDialog({Key key}) : super(key: key);

  @override
  _LoseDialogState createState() => _LoseDialogState();
}

class _LoseDialogState extends State<LoseDialog>{

  @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);

    return WillPopScope(
      onWillPop: () async => false,
      child: AlertDialog(
        content: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Image.asset(
              'assets/lose.gif',
              height: 35.0 * SizeConfig.blockSizeVertical,
            ),
          ],
        ),
      ),
    );
  }
}
like image 969
Evan Herchek Avatar asked Oct 30 '25 17:10

Evan Herchek


1 Answers

After some searching, I finally found a solution to my problem. I created the gif as an AssetImage and called the evict method on it as shown in the following GitHub issue.

https://github.com/flutter/flutter/issues/51775

like image 191
Evan Herchek Avatar answered Nov 02 '25 07:11

Evan Herchek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!