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)
CodePudding user response:
Try using:
AssetImage('assets/images/login.gif'),
You must include the key used in the pubspec.yaml
to load your asset.
CodePudding user response:
Try below code:
Image.asset("assets/images/login.gif",
gaplessPlayback: true, fit: BoxFit.fill)