Unable to load asset: packages in flutter

1.2k Views Asked by At

i want to add some image on my app, but when i add image asset, i cant load image from folder assets/images .when i start debugging its show an error like this

my images code its like this

Container(
             margin: EdgeInsets.only(top: 0),
             height: 250,
             color: kMainColor,
             child: Container(
               margin: EdgeInsets.only(top: 70),
               decoration: BoxDecoration(
                 image: DecorationImage(
                   image: AssetImage('assets/images/sawi1.jpg',
                       package: 'plantgo_alpha'),
                   fit: BoxFit.contain,
                 ),
               ),
             ),
           ),

and this my pubspec.yaml

flutter:
 uses-material-design: true
 assets:
  - assets/icons/
  - assets/images/

images path path

i try to fix with another question and answer in this forum but still error, i rly appreciate if somebody help me fix this

4

There are 4 best solutions below

1
On BEST ANSWER

For first you don't need to specify package. For second you have only one space before "assets:" and list of asset folders, it requires TWO spaces

enter image description here

2
On

This error happens commonly in Flutter when your app is already running & you add new images.

If your image path is correct, pubspec.yaml is correct then:

Try terminating & restarting the app.

NOTE: Also check the indentation in pubspec.yaml.

0
On

Be sure that the name of your image is typed correctly and that the type of the photo is correct in your image folder and your code. If you dragged the photos from the web or the cloud it's a common mistake that the photo is a hyperlink and not .jpg, .png, etc..If not you can still remove and add again your photos just to be sure. If neither of this worked be sure to provide ass a screenshot of your pubspec.yaml

0
On

if your assests included in android. Use this :

flutter:
  assets:
    -android/assests/directory/