216

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.png
ios
lib
 ui
  home.dart
 main.dart
test
.gitignore
.metadata
.packages
app_widgets.iml
pubspec.lock
pubspec.yaml
README.md

In my pubspec.yaml file, I load the fonts and assets like this

flutter:

uses-material-design: true

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

fonts:
  - family: Oxygen
    fonts:
      - asset: fonts/Oxygen-Regular.ttf
      - asset: fonts/Oxygen-Bold.ttf
        weight: 700
      - asset: fonts/Oxygen-Light.ttf
        weight: 300

I'm not getting any errors for this pubspec.yaml, and running flutter packages get gives an exit code of 0.

In my home.dart I have the following class:

class PizzaImageWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    AssetImage pizzaAsset = AssetImage('images/pizza0.png');
    Image image = Image(image: pizzaAsset, width: 400, height: 400);
    return Container(
      child: image,
    );
  }
}

Which I use elsewhere, in order to show the image (code omitted):

        ),
        PizzaImageWidget(),
      ],

The building gives no errors. Flutter Doctor -v doesn't give any errors, neither does Flutter Analyze -v. The .apk seems to build just fine but when the app opens up on my phone I get the following error in asset_bundle.dart:

Exception has occurred. FlutterError (Unable to load asset: images/pizza0.png)

The error is thrown by this class in the asset_bundle.dart file:

/// An [AssetBundle] that loads resources using platform messages.
class PlatformAssetBundle extends CachingAssetBundle {
  @override
  Future<ByteData> load(String key) async {
    final Uint8List encoded = utf8.encoder.convert(Uri(path: Uri.encodeFull(key)).path);
    final ByteData asset =
        await BinaryMessages.send('flutter/assets', encoded.buffer.asByteData());
    if (asset == null)
      throw FlutterError('Unable to load asset: $key');
    return asset;
  }
}

This happens both for the pizza0.png file as well as the pizza1.png file. The files are visible in the tree structure, both in Windows Explorer as in VS Code. The font assets load without issue.

This is the output I am getting when running Flutter Run -v:

[+1068 ms] I/flutter ( 6489): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ [ +9 ms] I/flutter ( 6489): The following assertion was thrown resolving an image codec: [ +2 ms] I/flutter ( 6489): Unable to load asset: images/pizza0.png [ +2 ms] I/flutter ( 6489): [ +1 ms] I/flutter ( 6489): When the exception was thrown, this was the stack: [ +2 ms] I/flutter ( 6489): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7) [ +1 ms] I/flutter ( 6489): [ +1 ms] I/flutter ( 6489): #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:429:44) [ +1 ms] I/flutter ( 6489): [ +1 ms] I/flutter ( 6489): #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:414:14) [ +1 ms] I/flutter ( 6489): #3 ImageProvider.resolve.. (package:flutter/src/painting/image_provider.dart:267:86) [ +4 ms] I/flutter ( 6489): #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:143:20) [ +3 ms] I/flutter ( 6489): #5 ImageProvider.resolve. (package:flutter/src/painting/image_provider.dart:267:63) [ +3 ms] I/flutter ( 6489): (elided 8 frames from package dart:async) [ +1 ms] I/flutter ( 6489): [ +1 ms] I/flutter ( 6489): Image provider: AssetImage(bundle: null, name: "images/pizza0.png") [ +3 ms] I/flutter ( 6489): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#20fc8(), name: "images/pizza0.png", [ +1 ms] I/flutter ( 6489): scale: 1.0) [ +2 ms] I/flutter ( 6489): ════════════════════════════════════════════════════════════════════════════════════════════════════

Matthias
  • 12,704
  • 13
  • 35
  • 56

51 Answers51

310

You should consider the indentation for assets

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

After all this, you can make a hot-restart.

diegoveloper
  • 93,875
  • 20
  • 236
  • 194
  • If I do that, flutter packages get fails: Running "flutter packages get" in app_widgets... Error on line 40, column 3 of pubspec.yaml: Expected a key while parsing a block mapping. assets: ^ pub get failed (65) exit code 65 – Matthias Dec 06 '18 at 21:34
  • just add two spaces – diegoveloper Dec 06 '18 at 21:35
  • Spaces where exactly? Right now I have the words flutter, and assets sticking all the way to the left with no spaces. If I add a space, or two, before the word assets I get the exit code 65 error. – Matthias Dec 06 '18 at 21:38
  • 2
    2 white spaces (or 1 tab) before assets and 4 white spaces (or 2 tabs) before - images... – diegoveloper Dec 06 '18 at 21:40
  • Nope. Gives the same error... This is my full file by the way: https://pastebin.com/ygzkTgHG – Matthias Dec 06 '18 at 21:42
  • 14
    Turns out the "uses-material-design: true" is the culprit here. Commenting that out, or changing the indendation of that part makes it work. Seems like a weird oversight/bug that the fonts work just fine like that but the assets don't. – Matthias Dec 06 '18 at 21:51
  • 1
    Matthias' comment above worked for me, but I should note that even with that set to true, SOME of my assets worked while others did not. It looks like it is just something incorrect on the flutter end. – PGMacDesign Jun 10 '19 at 17:16
  • Make sure that you are adding assets to "flutter:" not to "dependancies: flutter:" which is first one in the pubspec.yaml – Wojciechu Jul 24 '19 at 11:32
  • Matthias comment did the trick, commenting and uncommenting fixed it. Definitly something is wrong in flutter – Guillaume Petit Oct 23 '20 at 08:34
  • 1
    I also have the same issue when I was developing my first app with dependency. in pupspec.yaml . These are sensitves. This was a solution for me. – A.J Jun 04 '21 at 05:53
  • 1
    Thanks for the solution ...I spent a lot time on this. – Rockin Feb 26 '23 at 18:11
  • Yes. Don't forget assets is below (inside) flutter – Plugie Mar 11 '23 at 04:58
146

Running flutter clean solved my issue.

More about this error

genericUser
  • 4,417
  • 1
  • 28
  • 73
yathavan
  • 2,051
  • 2
  • 18
  • 25
  • 12
    Thanks. This was my problem. Actually I had the wrong indentation too. So people should check their indentation and also run `flutter clean`. – dan-gph Oct 08 '19 at 06:25
  • 1
    flutter clean worked. I wonder why pubspec.yml changes don't automatically run flutter clean – Golden Lion Mar 02 '20 at 12:29
  • 6
    From Android Studio, in my case the issue would happen only when using hot-reload. Triggering a rebuild by pressing the STOP button and then the PLAY button solved it (I'm using the integrated Android emulator) – Michele Apr 09 '21 at 22:12
  • 1
    @Michele I'm with you. I had to do the hot restart. That fixed it – Luigi Jun 20 '21 at 00:37
  • 1
    Restart Android Studio after running `flutter clean`. Worked for me. – Thomas David Kehoe Jan 03 '22 at 18:42
  • Worked for me as well, if you get a bunch of red "no references" just restart Android Studio. – Mike Schvedov Feb 17 '23 at 11:21
77

Considering your app will have multiple assets it is better to reference the assets folder and not the asset itself. Ensure you use proper indentations as the pubspec.yaml is indent sensitive.

flutter:

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

and then you can access the image asset by prefixing the referenced folder path

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

Note that when an asset’s path is specified in the assets section of pubspec.yaml, the build process looks for any files with the same name in adjacent subdirectories. Such files are then included in the asset bundle along with the specified asset.

See Adding asset variants section in the official flutter docs

Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
32

Encountered the same issue with a slightly different code. In my case, I was using a "assets" folder subdivided into sub-folders for assets (sprites, audio, UI).

My code was simply at first in pubspec.yaml- alternative would be to detail every single file.

flutter:

  assets:
    - assets

Indentation and flutter clean was not enough to fix it. The files in the sub-folders were not loading by flutter. It seems like flutter needs to be "taken by the hand" and not looking at sub-folders without explicitly asking it to look at them. This worked for me:

flutter:

  assets:
    - assets/sprites/
    - assets/audio/
    - assets/UI/

So I had to detail each folder and each sub-folder that contains assets (mp3, jpg, etc). Doing so made the app work and saved me tons of time as the only solution detailed above would require me to manually list 30+ assets while the code here is just a few lines and easier to maintain.

Alexandre Jean
  • 622
  • 2
  • 11
  • 19
  • 4
    On a side note - there are packages like audioplayers that will not load assets properly if you use code like plyer.play('assets/audio/sound.mp3') in your dart file widgets. While plyer.play('audio/sound.mp3') will load properly. That also can create some very frustrating debugging. So I wanted to add it. – Alexandre Jean Apr 07 '20 at 11:57
  • This worked for me. I had the same problem – Trần Trung Hiếu Jul 30 '21 at 13:32
29

For me,

  1. flutter clean,
  2. Restart the android studio and emulator,
  3. giving full patth in my image

    image: AssetImage(
      './lib/graphics/logo2.png'
       ),
       width: 200,
       height: 200,
     );
    

these three steps did the trick.

Deepak Jha
  • 1,539
  • 12
  • 17
11

I also had this problem. I think there is a bug in the way Flutter caches images. My guess is that when you first attempted to load pizza0.png, it wasn't available, and Flutter has cached this failed result. Then, even after adding the correct image, Flutter still assumes it isn't available.

This is all guess-work, based on the fact that I had the same problem, and calling this once on app start fixed the problem for me:

imageCache.clear();

This clears the image cache, meaning that Flutter will then attempt to load the images fresh rather than search the cache.

PS I've also found that you need to call this whenever you change any existing images, for the same reason - Flutter will load the old cached version. The alternative is to rename the image.

James Allen
  • 6,406
  • 8
  • 50
  • 83
11

inside pubspec.yaml, DON'T USE TAB!

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

example:

flutter:
  assets:
    assets/
Mahinthan177
  • 774
  • 1
  • 9
  • 9
10

Some times cache will create a problem so first run

flutter clean

after this run

flutter pub get
Amit Kumar
  • 1,503
  • 14
  • 11
9

Actually the problem is in pubspec.yaml, I put all images to assets/images/ and

This wrong way

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

Correct

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

i just Re-run My app instead of just hot Reload.

Arinzehills
  • 1,491
  • 10
  • 14
  • re-run the app solves the problem. i wasted my 10m time ignoring this answer and keep trying check syntax+tab/spaces etc.. :P – bondythegreat May 26 '21 at 01:30
7

In my case a restart didn't help.

I had to uninstall the app and then run everything again.

It did worked!

genericUser
  • 4,417
  • 1
  • 28
  • 73
  • one of the worst things about flutter, takes me 35 minutes to load an image every time – 68060 Mar 23 '22 at 14:18
  • Yeah me too, for some reason every time I hot restart, it always leads to the same error, namely throwing an image error into the `image_provider.dart` file to the `_loadAsync` method. I have to stop the debug session and start it again – Muhammad Faisal Oct 14 '22 at 03:42
7

if you're developing flutter packages, please add package param after image path like this:

AssetImage('images/heart.png', package: 'my_icons') // my_icons is your plugin name, in flutter plugin is also a package.

Here is the link from flutter docs https://flutter.dev/assets-and-images/#from-packages

KenChoi
  • 121
  • 1
  • 6
6

I haved a similar problem, I fixed here:

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

After, do:

Flutter Clean
Dharman
  • 30,962
  • 25
  • 85
  • 135
5

After you did all things and still not working, try:

flutter clean
flutter pub get

sometimes after updating pubspec.yaml file, it can not run pub get although it shows it is running.

try commands above

YMG
  • 498
  • 6
  • 15
4
  1. you should start image path with assets word:

image: AssetImage('assets/images/pizza0.png')

  1. you must add each sub folder in a new line in pubspec.yaml
Good man
  • 396
  • 4
  • 12
4

The only thing that worked for me to mention THE WHOLE PATH in the CODE. That is you must mention the image path from the root directory on the code page, in YAML it works with the top-level directory.

You probably can't get away only with the main directory path in code, I have tried a lot and that's the only thing that works.

hope it solved the issue and saved your time.

The 1st image is of code and the second is of the yaml.

code

yaml

Neail
  • 145
  • 9
4

There is clearly some sort of flutter bug. This is my directory structure:

<project>/assets/images/myimage.png

This is what I have in pubspec.yaml:

flutter:

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

And this is how it used to work and still works when I compile for web:

const DecorationImage(image: AssetImage("images/myimage.png")

But it will only work when I compile for ios like this:

const DecorationImage(image: AssetImage("assets/images/myimage.png")

Luckily adding "assets/" as a prefix works now in all cases.

Babao
  • 1,273
  • 1
  • 8
  • 3
3

While I was loading a new image in my asset folder, I just encountered the problem every time.

I run flutter clean & then restarted the Android Studio. Seems like flutter packages caches the asset folder and there is no mechanism to update the cache when a developer adds a new image in the project (Personal thoughts).

Ankur Lahiry
  • 2,253
  • 1
  • 15
  • 25
3

Make a habit to check pubspec.yaml when you are struggling to load an image in a Flutter project. Most of the time, the problem is with it.

The correct way is mentioned below. Do not use the Tab key to keep the spaces. Instead, use the Space bar.

flutter:
  uses-material-design: tru
  assets:
    - images/image1.jpg

And make sure you include the same correct path in your dart file.

  • One trick I always use is renaming the image with a very short name to avoid typo errors.

Hope this would be helpful to anyone who faces these kinds of problems.

SandaliTP
  • 795
  • 5
  • 7
3

If everything is ok, correct path, correct pubspec spaces, etc, the last thing that could cause this is cache. You can close the simulator and start your application again, it helps for my case.

Hieu Vo
  • 3,105
  • 30
  • 31
2

This is issue has almost driven me nut in the past. To buttress what others have said, after making sure that all the indentations on the yaml file has been corrected and the problem persist, run a 'flutter clean' command at the terminal in Android studio. As at flutter 1.9, this should fix the issue.

defemz
  • 519
  • 2
  • 7
  • 20
2

Another cause of similar problem: On Windows you should not use \ sign as directory separator. So

instead of

AssetImage('images\heart.png')

use

AssetImage('images/heart.png')

It can be a bug of Windows version of Flutter. It solved my problem.

Miki
  • 440
  • 4
  • 7
2

One more answer in the mix:

My pubspec.yaml looked like this:

flutter:
  assets:
    - assets/us_defs/
    - assets/eu_defs/
    - assets/images/

and in the invoking code:

Center(
  child: Image(
    image: AssetImage('assets/images/<name.png>')
  )
)

(The *_defs folders contain json files for various other purposes and I can load them just fine.)

But, the image wouldn't load, no matter what I tried. Checked and double checked the indent spacing, spelling, invoked flutter clean and flutter pub get, cold started the app, etc. Tried referencing 'images/<name.png>' vs 'assets/images/<name.png>'.

Nada.

Finally, I lifted the images folder to the top level under the project folder:

flutter:
  assets:
    - assets/us_defs/
    - assets/eu_defs/
    - images/    <-- now a top level folder

and in the invoking code:

Center(
  child: Image(
    image: AssetImage('images/<name.png>');
  )
)

... and that worked.

I have no idea why.

Now, I'd rather keep the images folder in assets since it fits my sensibilities, but if this reorg gets me going, I'll live with it.

rickb
  • 601
  • 5
  • 19
1

I had the same issue I corrected it, you just need to put the two(uses-material-design: true and assets) in the same column and click in the upgrade dependencies but before restart android studio.

screenshot

Gerard Roche
  • 6,162
  • 4
  • 43
  • 69
slydesign
  • 21
  • 2
1

Make sure the file names do not contain special characters such as ñ for example

1

Dec 25th, 2019 :

Whoever facing issue regarding Image not showing in Flutter , let me give you simple checkpoints :

  1. Image.asset('assets/images/photo1.png'); -- here make sure dont use / (forward slash ) before assets.
  2. YAML file always be clear dont use space , instead use TAB.
  3. YAML file add entries for assets. as mentioned in above comment.

First point is very important

Shobhakar Tiwari
  • 7,862
  • 4
  • 36
  • 71
1

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!

Parthasarathy S
  • 197
  • 1
  • 6
1

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.

Soropromo
  • 1,212
  • 12
  • 17
1

I was also facing the same issue . The issue on my side was that the image name was having the space in between its name so I updated the image name with the new name that does not have any space.

Image name creating the error was comboclr emtpy no circle.png

I updated this name to comboclr_emtpy_no_circle.png

Rakesh Verma
  • 766
  • 6
  • 14
1

I ran into this issue and very nearly gave up on Flutter until I stumbled upon the cause. In my case what I was doing was along the following lines

static Future<String> resourceText(String resName) async
{
 try
 { 
  ZLibCodec zlc = new ZLibCodec(gzip:false,raw:true,level:9);
  var data= await rootBundle.load('assets/path/to/$resName');
  String result = new 
  String.fromCharCodes(zlc.decode(puzzleData.buffer.asUint8List()));
  return puzzle;
 } catch(e)
 {
  debugPrint('Resource Error $resName $e');
  return ''; 
 } 
}

static Future<String> fallBackText(String textName) async
{
 if (testCondtion) return 'Some Required Text';
 else return resourceText('default');
} 

where Some Required Text was a text string sent back if the testCondition was being met. Failing that I was trying to pick up default text from the app resources and send that back instead. My mistake was in the line return resourceText('default');. After changing it to read return await resourceText('default') things worked just as expected.

This issue arises from the fact that rootBundle.load operates asynchronously. In order to return its results correctly we need to await their availability which I had failed to do. It strikes me as slightly surprising that neither the Flutter VSCode plugin nor the Flutter build process flag up this as an error. While there may well be other reasons why rootBundle.load fails this answer will, hopefully, help others who are running into mysterious asset load failures in Flutter.

DroidOS
  • 8,530
  • 16
  • 99
  • 171
1

My issue was nested folders.

I had my image in assets/images/logo/xyz.png and thought that - assets/images/ would catch all subfolders.

You have to explicitly add each nested subfolder

Solution: - assets/images/logo/ etc.

HJo
  • 1,902
  • 1
  • 19
  • 30
1

I put my images in a subdirectory of the assets folder. Whenever I add new images, I restart the application and it works fine.

 assets:
    - assets/sub_folder/

I do this so that I don't have to list each asset name.

user3344429
  • 160
  • 5
1

Well in case you have changed everything in the indentation part as told and checked for the typo errors but still get an error then you should do this simple which worked for me and it seems this is overlooked by almost everyone

even if you have correct spacing after the assets: you still might be doinbg this one thing wrong

keep the indentation in this order

flutter: <2_spaces>assets: <no_space>- assets/images/image.png

thus it should look like this

flutter:
  assets:
  - assets/images/image.png
1

I had the same error when trying to add an image to a module inside a larger project turns out the Image.asset widget takes a packages parameter that you can specify, after specifying it worked just fine

martinseal1987
  • 1,862
  • 8
  • 44
  • 77
1

first Check assets path in pubspec.yaml and also run flutter clean Command

Asim Khan
  • 309
  • 3
  • 2
1

The one thing that was missing from all of these (many duplicates) answers (for android) was this - The pubspec.yaml file needed (for me at least) to reference the asset file using direct reference (note the './' below):

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

Note that this assumes your assets/images folders are in the root of the project (the same folder that pubspec.yaml is in). This will allow any image in the images folder to be accessible:

child: Image(image: AssetImage("assets/images/Players.png"))
FreedomRings
  • 181
  • 1
  • 9
1
  assets:
    - assets/

It was working until I upgraded my Flutter version to 3.12.0 .

So the fix was for me to load images was to change it like below

  assets:
    - assets/images/
touhid udoy
  • 4,005
  • 2
  • 18
  • 31
0

This error occurs in when images are not properly updated in pubspec.yaml

Follow the steps to add a image to flutter:

1)create assets folder in project(inplace of assets you can create as your wish like images or else). creating assets directory in project

2)add images into assets folder(or drag and drop image to assets). adding images into assets folder

3)open pubspec.yaml file create a assets dependency and add a images which are already available in assets folder and run command from terminal pubget or press ctrl+s to save it will run and update,or press the download arrow which appears in top to update, once updated successfully in output console you can see exitcode 0..

follow the above picture: create a assets dependency and add a images which are already available in assets folder and run command from terminal pubget or press ctrl+s to save it will run and update images ,or press the download arrow which appears in top to update images, once updated successfully in output console you can see exitcode 0.

Suresh B B
  • 1,387
  • 11
  • 13
0

using

Image.asset( 'assets\\images\\logo.png')

worked for me, need to specify the relative image path in puspec.yaml file

0

For Android Studio Bumblebee 2021.1.1: If you have your asset path in pubspec.yaml file set to 'images/' or whatever naming you have preferred then

flutter clean

OR you can go to Tools -> Flutter -> Flutter clean

& then hot-restart should fix the problem.

Suhail
  • 324
  • 1
  • 15
0

I was having same problem and I found no problem in pubspec.yaml. However, restarting vscode worked for me

user2462948
  • 87
  • 1
  • 5
0
Image.asset('images/heart.png', fit: BoxFit.cover,width: 450, ),

Setting the width worked for me.

Krishan Madushanka
  • 319
  • 1
  • 5
  • 21
0

This maybe happens because Windows OS uses \ as a directory separator. you can do this:

You can create a “raw” string by prefixing it with r:

AssetImage(r'images\icon.png')

or

use the forward slash /

AssetImage('images/icon.png')
TOZX
  • 181
  • 1
  • 8
0

I have facing this problem. I do flutter clean, I do Hot Restart, check the pubspec.yaml. But everything seems fine.

My problem is at the file name, please check your lower case and upper case of your filename.

My problem is like this.

file name

images/Pizza0.png

error

AssetImage pizzaAsset = AssetImage('images/pizza0.png');

work

 AssetImage pizzaAsset = AssetImage('images/Pizza0.png');
Tri yulianto
  • 323
  • 2
  • 7
0

If you are working in a project with many modules could be the case of your module is not accessing the right assets folders. To fix this you have to specify your package name:

Using Flutter SVG

SvgPicture.asset("assets/images/image1.svg", package: "<my_package_name>", width: 100, height: 100,),

Using Image.asset

Image.asset(AssetImage("assets/images/image1.png").assetName, package: "<my_package_name>",);

and don't forget of specifying your assets in pubspec.yaml:

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

Refer to this question for further details

Isac Moura
  • 5,940
  • 3
  • 13
  • 27
0

If everything is as it should be and problem still exist.

Here is my suggestion :

Write specified path in "pubspec.yaml".

  assets:
- assets/images/x.png

After pub get, yellow line will appear to tell you file doesn't exist.

Then Refactoring your file name will make disappear that yellow line and ide will recognize your existing file.

Hope it helps.

0

In pubspec.yaml check the indent in assets and in assets set lines. In assets line it should be 1 tab or 2 space, and in assets set line, it should be 2 tab or 4 spaces.

  assets:
    - assets/1.jpeg

[1 Tab or 2 space] assets:

[2 Tab or 4 space] - assets/1.jpeg

enter image description here

After all is done restart the app. Remember Don't use hot reload or hot restart. It won't work.

Pankaj Lahoti
  • 2,792
  • 1
  • 7
  • 8
0

if you think everything is ok in pubsepec.yaml . and you wrote the path of the image well then do the following :

1-Fixed By Running : =>flutter clean then => flutter pub get

2-close your app and remove it from background apps and => run it again

it should appears now ✅

0

For windows

In my case I has to change Image.asset to Image.file:

from:

Image.asset(r"C:\path\to\file");

to:

Image.file(File(r"C:\path\to\file");
Lenny4
  • 1,215
  • 1
  • 14
  • 33
-1

In my case, I had to run pod install in the iOS dir again

Rudolf J
  • 517
  • 4
  • 10
-3

Please provide the exact image name(including the extension) as specified in the images folder. A mismatch can trigger this exception.

Singh
  • 2,151
  • 3
  • 15
  • 30