Solution 1 :
Subdirectories within a directory are not automatically included. You need to include every directory in your pubspec.yaml. Not sure how things worked on the emulator without this. So you would have (according to your asset structure):
assets:
- assets/images/Antiguo
- asests/images/Aparicion
...
Since the assets are within the assets/
folder, you also need to include that in your path:
Image.asset('assets/images/Kratos/kr1.jpg', ...);
Do a flutter clean
and try building again.
Solution 2 :
are you getting any error in your terminal like: “Image not found or similar”, the first thing I saw from your image which isn’t too clear is that when you establish your images path in the pubspec.yaml you must be very carefull with spacing, it seems to me that you added one space instead of 2 and dont forget to add every subdirectory in you’re case you’re missing to add the directory of “Kratos”:
assets:
- assets/images/Kratos
So it would be like this:
[Space][Space]assets:
[Space][Space][Space][Space]-[Space]assets/images/Kratos
That should work wonders, hope I was able to give you any help.
Problem :
I have created an app in flutter and when I test it on my mobile it does not show any image. Everything is fine, except the images.
I attach a picture of the pubspec.yaml, as I have the structure of assets and the cmd of how I create the apk. Each name in the images is a folder in which there are images inside.
I clarify that in Visual Studio Code that is where I have done it, in its emulator if the images are shown, but when I install the apk, no.
It is curious that if I add – assets/images/Atreus/ , when creating the apk, this weighs more (as it weighs more for that folder I added), but still not shown.
Thanks.
ADD: I have already fixed the red warning. It creates the apk without those warnings (I updated jdk to 15 and gradle to version 7.0.2), but the images are still not visible.
Code image:
Image.asset(
'images/Kratos/kr2.jpg',
width: 100,
height: 100,
fit: BoxFit.cover,
),
Code image updated:
Code image:
Image.asset(
'assets/images/Kratos/kr2.jpg',
width: 100,
height: 100,
fit: BoxFit.cover,
),
NEW: Now I get this error. I have version 1.5 on my computer but I don’t know how to select it.
Now, when I change the version manually in build.gradle ext.kotlin_version = ‘1.5’ I get this error, and even if I do flutter clean again it doesn’t fix the problem.
Ok. Beginner’s mistake. I put the version ‘1.5’ but I should have put ‘1.5.0’ … Similarly, the apk is created without fail but the images are not displayed.
NEWS: Images are already shown! Many thanks to user2233706. I can’t give points for being a “newbie” but I appreciate it very much.
Comments
Comment posted by user2233706
You should put formatted code in your question, not images of it.
Comment posted by Brilosan8
I have added one thing
Comment posted by user2233706
I’ve had issues where building twice mysteriously fixes the issue. But you can set the kotlin version in
Comment posted by Brilosan8
I have added what happens now
Comment posted by user2233706
Can you try debugging on the device? Maybe you’ll see some errors in the debug console. From VSCode you can choose your device from the lower right, assuming you have USB debugging enabled. You also need to post a minimal example that reproduces the problem.
Comment posted by Brilosan8
I have done flutter clean and flutter pub get and the images still do not appear in the apk. Please help.
Comment posted by Brilosan8
I have already put the image of the code I use for the image.