FlutterError: Unable to load asset

后端 未结 22 3271
死守一世寂寞
死守一世寂寞 2020-11-30 10:31

This is the folder structure of my app

.idea
.vscode
android
build
fonts
 Oxygen-Bold.tff
 Oxygen-Light.tff
 Oxygen-Regular.tff
images
 pizza0.png
 pizza1.pn         


        
相关标签:
22条回答
  • 2020-11-30 11:28

    After declaring correctly in pubspec.yaml, consider giving full path of the image ex.

    'assets/images/about_us.png' 
    

    instead of just images/..

    worked for me after wasting 2 hours on such a trivial error.

    0 讨论(0)
  • 2020-11-30 11:30

    I have the same issue. I've just run "$ flutter clean", then everything is OK.

    More about this error

    0 讨论(0)
  • 2020-11-30 11:36

    Don't struggle to add the path to each image asset, instead just specify the path to your images directory.
    just make sure you use proper indentations as the pubspec.yaml is indent sensitive.

    flutter:
    
      uses-material-design: true
      assets:
        - images/
    

    and you can simply access each image as

      new Image.asset('images/pizza1.png',width:300,height:100)
    
    0 讨论(0)
  • 2020-11-30 11:36

    This issue still existed in my case even after, flutter clean (deletes build folder) and proper indentations in yaml file

    It got fixed by itself, as it could be an issue related to Android Studio.

    Fix 1) Restart the emulator in Cold Boot mode, In Android Studio, after clicking List Virtual Devices button, click Drop down arrow (last icon next to edit icon) => Choose Cold Boot Now option. If issue still exist, follow as below

    Fix 2) After changing the emulator virtual device as a workaround,

    For Example : From Nexus 6 to Pixel emulator

    --happy coding!

    0 讨论(0)
提交回复
热议问题