0

I'm trying to add a gif from the local assets folder. Flutter throws an error named "login.gif" even though I checked multiple times if my folder structure or file name or path is correct or not or I didn't imported the path in the pubspec.yaml. But there's not a single mistake.. Tried searching for the answer everywhere but couldn't solve the issue! I'm a complete beginner in flutter...

home: const Scaffold(
    body: SafeArea(
      child: Image(
        image: AssetImage('login.gif'),
      ),
    ),
  ),

pubspec.yaml file:

  assets:
    - assets/images/

The Error:

======== Exception caught by image resource service 
================================================
The following assertion was thrown resolving an image codec:
Unable to load asset: /login.gif
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "login.gif")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#08feb(), name: 
"login.gif", scale: 1.0)

3 Answers3

1

Try using:

AssetImage('assets/images/login.gif'),

You must include the key used in the pubspec.yaml to load your asset.

Alex Rintt
  • 1,618
  • 1
  • 11
  • 18
1

Change

image: AssetImage('login.gif')

to

image: AssetImage('assets/images/login.gif')

If this doesn't solve your issue,

Follow this question : how to display animated gif in flutter?

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
0

Try below code:

Image.asset("assets/images/login.gif",
                gaplessPlayback: true, fit: BoxFit.fill)
Rohan Jariwala
  • 1,564
  • 2
  • 7
  • 24