Juan Casas
Juan Casas

Reputation: 104

unable load image asset in flutter

I am not sure why my images from assets is not working

I looked at these two questions:

-https://stackoverflow.com/questions/64158543/flutter-unable-to-load-image-asset

-https://stackoverflow.com/questions/67552389/unable-to-load-image-asset

this is how I am trying to fetch the image:

          Image(
            image: AssetImage('assets/logo.png'),
            width: 100,
            height: 100,
          ),

here is my pubspec.yaml

 assets:
    - assets/logo.png
    - assets/back.png


below is the file structure this is the file structure

I tried following videos on youtube but that didnt work.

any suggestions are welcome

Upvotes: 0

Views: 1758

Answers (4)

KAVIN RORONOA
KAVIN RORONOA

Reputation: 9

Code in the pubspec.yaml should be correct and run flutter pub get and you'll be fine.(It worked for me!)

Upvotes: 1

Juan Casas
Juan Casas

Reputation: 104

I ended up restarting the app then everyting worked

Upvotes: 0

Nams
Nams

Reputation: 302

if your images are in images folder of assets folder then declare as below in pubspec.yaml

assets:
  - assets/images/

And write code to get image as below

Image(
        image: AssetImage('assets/images/logo.png'),
        width: 100,
        height: 100,
      ),

Upvotes: 2

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14775

Try below code and change your pubspec.yaml file like-

if your images in images folder

 assets:
    - assets/images

if your images in assetsfolder

 assets:
    - assets/

after that run command flutter pub get and Stop the code and re-run again

Refer assets-and-images

Upvotes: 1

Related Questions