Release bundle is not setting up properly assets folder in flutter web
Asked Answered
S

1

6

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:

enter image description here

When I run the command flutter web build --release I get a bundle with my images located the next way:

enter image description here

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/
Semiskilled answered 16/8, 2022 at 17:50 Comment(2)
Hi, Esteban! Can you please share your pubspec.yaml file, in particular, the declaration of your assets under flutter?Irma
@Irma Sure, I've added the section you mentioned at the end of the post!Qoph
I
3

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!

Infanta answered 28/11, 2022 at 21:16 Comment(1)
it's strange but it works. Thanks.Toting

© 2022 - 2024 — McMap. All rights reserved.