How to Solve Unable to load asset in Flutter?

· 3 min read
How to Solve Unable to load asset in Flutter
How to Solve Unable to load asset in Flutter

Every mobile application requires to display predefined images stored in an assets folder. Sometimes Flutter displays an error that says “Unable to load assets“. So in this article, We will learn about how to Solve Unable to load assets in Flutter.

How to Solve Unable to load assets in Flutter?

Kindly follow the below Step by Step instructions to Solve Unable to load assets in Flutter.

Go to pubspec.yaml and consider an indention for assets like below:

flutter:

  assets:
    - images/pizza1.png
    - images/pizza0.png

More details:

flutter:

[2 whitespaces or 1 tab]assets:
[4 whitespaces or 2 tabs]- images/pizza1.png
[4 whitespaces or 2 tabs]- images/pizza0.png

Here rather than adding the path to each image asset just specify the path to your images directory.

Just make sure you use proper indentations as the pubspec.yaml is indented sensitive.

flutter:

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

and you can simply access each image like below:

new Image.asset('images/pizza1.png',width:300,height:100)

So users can also try the below steps:

  • flutter clean
  • Restart the android studio and emulator,
  • giving full path in my image
    image: AssetImage(
      './lib/graphics/logo2.png'
       ),
       width: 200,
       height: 200,
     );

    Users can also try things like the below:

    inside pubspec.yaml, DON’T USE TAB!

  • flutter:
    <space><space>assets:
    <space><space><space><space>assets/

    example:

    flutter:
      assets:
        assets/

    It gets 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 the List Virtual Device button, click the Dropdown arrow (last icon next to edit icon) => Choose Cold Boot Now option. If the issue still exists, follow as below.

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

Conclusion:

Thanks for being with us on this Flutter Journey!!

Share it with your friends and colleges to improve overall knowledge!!

So that’s it for today.

Still, need support for Flutter Development? We Would love to assist you with Flutter. So leave a comment below.

Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

Flutter Agency is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.

3 comments

  1. Seem sometimes Android Studio not sync the asset we addded although I cleared cache and ran command “flutter pub get”.
    Have to restart computer.
    Thanks.

Leave a Reply