Flutter assets error: EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE

前端 未结 9 1738
借酒劲吻你
借酒劲吻你 2021-01-05 09:17

flutter can not find my images assets, what can I be doing wrong?

I got the error on debugger:

Launching lib/main.dart on XT1097 in debug mode... Built build

相关标签:
9条回答
  • 2021-01-05 09:37

    As far as I know currently only files directly placed under the registered directory are added to assets.

    This should work:

    flutter:
      uses-material-design: true
      assets:
       - assets/images/
       - assets/images/user/
    
    0 讨论(0)
  • 2021-01-05 09:38

    I had the same error. In my case it was because the emulator of the phone that I am using does not have access to the internet.

    Run the application on a physical mobile device and it worked immediately.

    Solution connect the emulator to the internet.

    0 讨论(0)
  • 2021-01-05 09:40

    In my case I have to correct the alignments between my assets and the uses-material-design lines in pubspec.yaml.

    flutter:
        uses-material-desgin: true
        assets:
            - images/3.jpg
    
    0 讨论(0)
  • 2021-01-05 09:40

    In my case, while i was using relative path like that Image.asset('./../images/welcome.png'), it doesn't work.

    But if i use absolute path like that Image.asset('images/welcome.png'), it works !

    0 讨论(0)
  • 2021-01-05 09:42

    Previously I set images paths as following

    "assets/images/SU.jpg"
    

    then I had this error so I changed it as following

    "images/SU.jpg"
    

    then it worked!!

    0 讨论(0)
  • 2021-01-05 09:46

    This is how this resolved for me.

    Previously I was using the exact paths to images as suggested

     assets:
     - assets/logo_linked_in.jpg
     - assets/logo_medium.png
     - assets/logo_stackoverflow.png
     - assets/myself.jpg
     - assets/sparta.jpg
     - assets/fox.png
    

    Then I tried just the parent directory name, which was just using:

    assets:
     - assets/
    

    Voila! It worked like a charm!

    I hope this helps someone.

    P.S. - For newbies like me:

    Make sure you have correctly indented the pubspec.yaml as this is very important for the build.

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