Flutter image is not showing

Tamir Abutbul :

I want to show some local image and display it on the screen like this:

 Image(image: AssetImage('assets/images/addFood.png'))

But I cannot see the image on the screen and I am getting no error at all.

Here is what I have done:

In my pubspec.yaml I have added my image folder like this:

  assets:
    - lib/assets/images/

The image named "addFood" is inside images folder as you can see here:

enter image description here

I want to display a simple text with image under it, I can see the text on the screen and I am doing it like this:

  Widget build(BuildContext context) {

    if (favoriteMeals.isEmpty)

    return Column(children: <Widget>[
      Text('no favorites',style: Theme.of(context).textTheme.title,),
      Image(image: AssetImage('assets/images/addFood.png'))
    ]);

    else{
     ......
     ......
     ......
   }

All I can see is the text without the image:

enter image description here

solutions that did not help in my case:

AssetImage is not not displaying image in flutter app

Adding assets and images

mage Not Appearing when Using "new Image.asset" inside a Column

How can I fix it and make sure that the image will be displayed on the screen?

Christopher Moore :

You need to provide the full path for an asset when accessing it within the code. Nothing is implied when accessing the assets. Your actual path is lib/assets/images/, but you only do assets/images/. Change your code to include this:

Image(image: AssetImage('lib/assets/images/addFood.png'))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related