Error showing a Flutter image

3

Hello community, I hope you are having a good day. Sorry for the inconvenience, what happens is that I am new to the development with Flutter and I am trying to display an image but it does not show it and it does not stop throwing a warning that says it is not possible to show the image, I understand that I must create my assets directory which is already and I must add it to the pubspec.yaml file which I already did and I have it in the following way:

uses-material-design: true
assets:
  - lib/assets/

and I'll call the image in this way:

Image.asset('logo.png')

Just my directory is in the path specified above and my image is there with that name but it does not stop showing me the error that can not show it. If you can help me, I'll be very grateful.

Thank you in advance, I wish you the best and have an excellent day. Blessings to all.

    
asked by Miguel Gonzalez 01.11.2018 в 17:12
source

2 answers

2

It is necessary that you use the full path when you show the image, like this:

Image.asset("lib/assets/logo.png")
    
answered by 01.11.2018 / 17:21
source
-2

The correct way would be to define the resource or directory that contains the resources within your yaml file, for example:

flutter:
  assets:
    - lib/assets/
    - lib/assets/logo.png

if within lib/assets you contain the image logo.png , it would be done in this way defining the complete path of the image:

 image: AssetImage('lib/assets/logo.png'),

or the way you want to do it:

 new Image.asset('lib/assets/logo.png')

Review the documents:

Flutter: uploading images (English)

AssetImage Class (English)

    
answered by 01.11.2018 в 19:51