0

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

skyward17
  • 89
  • 2
  • 12

4 Answers4

0

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.

Ravi Singh Lodhi
  • 2,605
  • 1
  • 9
  • 12
  • i already done this too many times for restaring the app, then its stiil error. and i do check identation on another comment like this . flutter: [2 whitespaces or 1 tab]assets: [4 whitespaces or 2 tabs]- images/icons/ [4 whitespaces or 2 tabs]- images/images/ – skyward17 Dec 15 '20 at 06:54
  • Who downvoted my answer when it was already correct? I mentioned the indentation check in my answer also which was the case in this question. – Ravi Singh Lodhi Dec 17 '20 at 08:37
0

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

Jordan Kotiadis
  • 558
  • 6
  • 21
0

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

0

if your assests included in android. Use this :

flutter:
  assets:
    -android/assests/directory/