Flutter web can't load network image from another domain

自古美人都是妖i 提交于 2021-02-19 04:13:51

问题


I can't load network images in flutter web from other domains with API calls. getting this error

Trying to load an image from another domain? Find answers at: https://flutter.dev/docs/development/platform-integration/web-images ImageCodecException: Failed to load network image.

any help?


回答1:


For being able to display your images from Firebase Storage on a Flutter web page you have to configure your data for CORS.

  1. Open the GCP console, select your project and start a cloud terminal session by clicking the >_ icon button in the top navbar.
  2. Click the open editor button (pencil icon), then create the cors.json file.
  3. Run gsutil cors set cors.json gs://your-bucket

The cors.json file should look like this:

[
  {
    "origin": ["*"],
    "method": ["GET"],
    "maxAgeSeconds": 3600
  }
]

I set the origin to * which means that every website can display your images. But you can also insert the domain of your website there to restrict the access.

If you need more information: https://cloud.google.com/storage/docs/configuring-cors




回答2:


i solve this issue by using html renderer

flutter build web --release --web-renderer html

             



回答3:


I had this problem as well. It seems the latest beta version is creating an error. I downgraded using git checkout 1.25.0-8.3.pre in my flutter folder.



来源:https://stackoverflow.com/questions/65653801/flutter-web-cant-load-network-image-from-another-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!