flutterandroid-studiodartflutter-android

How do i add a gif in flutter


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)

Solution

  • 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?