skip to Main Content

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

3

Answers


  1. Chosen as BEST ANSWER

    I ended up restarting the app then everyting worked


  2. 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

    Login or Signup to reply.
  3. 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,
          ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search