close
unable to load asset, Unable to load asset Flutter, load asset in flutter, Unable to load asset in Flutter

[Solved] Unable to load asset Flutter

Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. You might face Unable to load asset this error in a flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How to solve Unable to load asset Flutter ?

  1. How to solve unable to load asset in flutter

    to solve unable to load asset in flutter Generally this error cause of wrong indentation for assets in pubspec.yaml file, Not given proper path and extra whitespace in pubspec.yaml file. So here is all possible method to solve this error.

  2. unable to load asset in flutter

    to solve unable to load asset in flutter Generally this error cause of wrong indentation for assets in pubspec.yaml file, Not given proper path and extra whitespace in pubspec.yaml file. So here is all possible method to solve this error.

Solution 1 : consider the indentation for assets.

Causes of this error is as below.

  1. Wrong indentation for assets in pubspec.yaml file.
  2. Not given proper path.
  3. Extra whitespace in pubspec.yaml file
  •  consider the indentation for assets.
flutter:

  assets:
    - images/assets.png
    - images/assets.png
  • Indentation right method Example
flutter:

[2 whitespaces or 1 tab]assets:
[4 whitespaces or 2 tabs]- assets/image1.png
[4 whitespaces or 2 tabs]- assets/image2.png

Solution 2: flutter clean

  1. flutter clean,
  2. Restart the android studio and emulator,
  3. giving full path in my image
image: AssetImage(
  'assets/image1.png'
   ),
   width: 300,
   height: 300,
 );

Solution 3: add each sub folder in a new line in pubspec.yaml

  1. You should start image path with assets word: image: AssetImage('assets/image1.png')
  2. you must add each sub folder in a new line in pubspec.yaml
  3. then dont forgot to run flutter clean.

So it’s all About All possible solutions. Hope this above all solution helped you a lot. Comment below Your thoughts and your queries. And Also Comment on your suggestion here.

Solution 4: Use this indentation

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

example:

flutter:
  assets:
    assets/

Also Read

Comments

3 responses to “[Solved] Unable to load asset Flutter”

  1. Chandan MG Avatar
    Chandan MG

    i done all the above solutions, but i still facing that exceptin, please help me out in this.

    1. Milan Dhameliya Avatar

      Can you please share your assets folder screenshot, pubspec.yaml file and file where you are using assets ?
      also i recommend you to uninstall and reinstall app after load assets

  2. Eduardo Avatar
    Eduardo

    Great!! flutter clean solve my problem! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *