Reputation: 374
I have created a flutter web application that uses some image assets. I have set these images at the root level project inside a folder called assets, so:
When I run the command flutter web build --release
I get a bundle with my images located the next way:
The problem is that my images are not recognized once the application has been deployed. To get my web application working right I have to relocate manually all files to the way I set them initially, like in the first image.
I have noticed this started to happen since I upgrade to flutter 3.0.0.
Does anyone know how to solve it or why does it happen? Is very annoying and likely to have an error doing that always when you want to have a new deployement. Thanks in advance for your help!
This is the way I declared my assets in the pubspec.yaml file:
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
- assets/svg/
- assets/svg/menu/
Upvotes: 6
Views: 1264
Reputation: 3910
I've found the issue, but is not clear why this was working previously locally.
First, I rename the assets
folder in root of the project to resources
(this is not solving the issue)
Second I fixed the path when showing the image.
(previously I loaded the image like this, and it was working always locally. But not when deployed!)
SvgPicture.asset("images/logo.svg")
SvgPicture.asset("resources/images/logo.svg")
and after deploy it, it started working correctly.
Summary: Please make sure that when loading media/assets, that path includes all folder hiearchy!
Upvotes: 3