1

I have an animated gif in my assets folder. I want to use it on my app login page but How? I used this code:

          Image.asset(
            "login.gif",
            height: 125.0,
            width: 125.0,
          ),

but it is not doing any thing.

this is the error:

I/flutter (31581): The following assertion was thrown resolving an image codec: I/flutter (31581): Unable to load asset: login.gif

Md.shah
  • 48
  • 1
  • 8
  • Where in the project tree is the gif stored? What does your `pubspec.yaml` assets section look like? – Christopher Moore May 13 '20 at 20:19
  • Does this answer your question? [how to display animated gif in flutter?](https://stackoverflow.com/questions/51556356/how-to-display-animated-gif-in-flutter) – Roy May 14 '20 at 06:20

2 Answers2

2

You have to give the relative path of the gif from assets not just the file name.

Try this..

Image.asset('assets/login.gif', width: 15.0, height: 15.0)

Also make sure that you have mentioned it in your pubspec.yaml.

srikanth7785
  • 1,382
  • 1
  • 7
  • 22
0

Get rid of the leading / in your path to the gif. It should be assets/login.gif

Also, consider using the cleaner Image.asset constructor, for example:

new Image.asset('assets/login.gif', width: 125.0, height: 125.0)
srikanth7785
  • 1,382
  • 1
  • 7
  • 22
guccisekspir
  • 1,359
  • 1
  • 9
  • 29