问题
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.
- Open the GCP console, select your project and start a cloud terminal session by clicking the
>_
icon button in the top navbar. - Click the open editor button (pencil icon), then create the
cors.json
file. - 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