-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to load Asset - wrong indentation in pubspec.yaml #11199
Comments
Is your "assets" key underneath a |
Man do I feel dumb. I just needed to tab the assets over so that they are under |
What is a flutter key ? I right clicked project file to make a directory called assets ? Is this not the correct way ? |
@Dano79 |
in pubspec....one tab makes all the difference... |
Thank you @shashankrshukla ...U saved my Day....!!!! |
@shashankrshukla fixed my problem as well , thx |
I am getting the same error when I run my code initially on my device but once I hot reload/restart the app, the app works just fine. Please help me out. |
I had the same problem. I had my images inside assets/ and in the pubspec.yaml I had this.
All I needed to do is change it to this:
|
@daanvandenhoek that shouldn't be necessary and just flutter:
assets:
- assets/ should have the same effect since about beta 0.6.0 (or a bit earlier - don't remember exactly when it was added). |
@shashankrshukla Thank you so much! problem was just due to a simple "Tab". I mean it didn't work when it was like this:
but then i just added a tab space before the "assets:" then it worked
|
I had done the same thing but still the image is not loading. Please help! |
@rohanmittal53 Please consider asking support questions in one of the other channels listed at http://flutter.io/support . |
try to make a full restart |
clean flutter it will solve the problem |
How do i add an image that can be seen in a flutter app... I have read this whole article 5 times and still can not make heads or tails out of it |
I just ran into this missing We should find a way to recognize this failure mode and provide a helpful warning. |
@HansMuller I also run into this recently and I think a main problem is that using the IDE feature to comment/uncomment results in an invalid state (1 redundant space). To probably the template should be changed to remove the space after # assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg and all other lines that might be uncommented and then customized |
Tks,
I also learned you can put
- assets
- images/
So you don't have to list all images
Imagine if your app had 100 images
…On Sun, Jan 27, 2019, 7:45 AM Günter Zöchbauer ***@***.*** wrote:
@HansMuller <https://github.com/HansMuller> I also run into this recently
and I think a main problem is that using the IDE feature to
comment/uncomment results in an invalid state (1 redundant space). To
probably the template should be changed to remove the space after # in
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
and all other lines that might be uncommented and then customized
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#11199 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Arh4gjdL9VmGpssffq2M11-BBFS6trMJks5vHcmIgaJpZM4OXO_l>
.
|
My issue was for those with same problem as mine If you have sub-directories in the assets folder, then using
will not include sub-directories. Use instead:
|
@erikkubica comment regarding sub-directories worked for me. |
It shouldn't be, but this was broken for a while and only fixed in the last 2 or 3 dev releases. Can you confirm which flutter version you are on? |
Do you remember which version exactly it was fixed on? |
I did a test on another project with the same problem and it worked, I was wrong. |
Anyone getting this issue with embedded android + flutter? |
I changed "F" to "f" and it worked for me :)
|
same problem here
until now it hasn't worked |
@arvie86 You should write like this in your pubspec.yaml:
and write like this in your ***.dart:
maybe you wrote in |
sir, i love you. |
Thanks for the answer, but Im successfull solve this problem just add "lib" before assets. Like this : flutter:
Image.asset('lib/assets/monkey.png') |
A common mistake is when you create the assets directory in the wrong place. |
and this not flutter:
assets: |
Looks like the conversation here has converged on making sure that folks use the correct indentation and syntax in their pubspec. Since this isn't a Flutter issue, I'm closing this issue. |
@kf6gpe Just to clarify, this is not what's actually happening. at the time I had the issue, I tried all those suggestions and none worked for me. I'm not sure if people are confusing the issue with something else and then thinking it's the solution, or perhaps people experience the problem differently, but either way none of the above was the solution. However, flutter has been upgraded and I haven't had that issue since, so I think closing the issue until someone else will experience it (and all above suggestions won't work for him) is a good idea at the moment. |
Try tab instead of space between "-" & image tag |
Indentation error. `> > flutter:
|
When I first ran the program, I received this message : but after hot reload Everything worked fine.so I noticed that the problem was with the space in the file address |
I tried all above but that worked thank you. |
This comment thread is interesting a lesson in why YAML is shit. One of the reasons it is shit anyway! Here are some more people being screwed by YAML:
Probably too late to choose a saner format for pubspec, but it would be nice if the "Unable to load asset" error listed the assets that are present, at least in debug mode. It might help people (especially people like me who have indented things properly but still get this error :-/ ). |
for me the problem was, that I was using dart package instead of flutter. I was using this: instead of: after changing that, it worked for me. |
You beauty,it worked like a charm |
I was using \ instead of / in the path so I was getting this problem |
If you still get an error after trying all of the above, check if there is no slash infort of the path in your dart file: It shoul be: |
I'm sure there is nothing wrong with my code or file path, I tried all those suggestions and none worked (Android Studio v.3.1.4) |
The following assertion was thrown resolving an image codec: When the exception was thrown, this was the stack: same error and my assets is arrange //pubsec.yaml flutter: |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
I downloaded some images to put into my app as Assets instead of Network images. I saved those images in a directory on my project called "Images". I saved those images as assets in the pubspec.yaml
I try to load the cat.jpg image with this line of code
new Image(image: new AssetImage('images/cat.jpg'))
. But I get this errorNetwork images load fine but any assets don't.
Logs
flutter run -d all
Flutter Doctor
The text was updated successfully, but these errors were encountered: