admin管理员组文章数量:1406926
I am using Flutter web for my application.
I used --web-renderer html
previously but now I have updated Flutter which no longer supports web-rendering flags.
This is how my code looks like.
CachedNetworkImage(
imageUrl: imageUrl,
height: height,
width: width,
fit: BoxFit.cover,
placeholder: (context, url) => Container(
color: Colors.grey[300], // Placeholder color
height: height,
width: width,
child: Center(child: CircularProgressIndicator()),
),
errorWidget: (context, url, error) {
debugPrint("$error");
debugPrint("$url");
return Container(
color: Colors.grey[300], // Background color if error occurs
height: height,
width: width,
child: const Icon(Icons.error, color: Colors.red),
);},
),
When I print the error, it shows EncodingError: The source image cannot be decoded.
The url is also correct and works fine in browser. Images are stored in Firebase storage
All results in Stackoverflow are talking about web renderer and base64 encoding, which I dont think is the issue here.
Any suggestions or help?
I am using Flutter web for my application.
I used --web-renderer html
previously but now I have updated Flutter which no longer supports web-rendering flags.
This is how my code looks like.
CachedNetworkImage(
imageUrl: imageUrl,
height: height,
width: width,
fit: BoxFit.cover,
placeholder: (context, url) => Container(
color: Colors.grey[300], // Placeholder color
height: height,
width: width,
child: Center(child: CircularProgressIndicator()),
),
errorWidget: (context, url, error) {
debugPrint("$error");
debugPrint("$url");
return Container(
color: Colors.grey[300], // Background color if error occurs
height: height,
width: width,
child: const Icon(Icons.error, color: Colors.red),
);},
),
When I print the error, it shows EncodingError: The source image cannot be decoded.
The url is also correct and works fine in browser. Images are stored in Firebase storage
All results in Stackoverflow are talking about web renderer and base64 encoding, which I dont think is the issue here.
Any suggestions or help?
Share Improve this question asked Mar 6 at 11:29 Zee AZee A 1531 silver badge7 bronze badges 8 | Show 3 more comments2 Answers
Reset to default 2This isn't encoding issue. As from the comments below your question, it looks like CORS for your Firebase bucket has not been set.
- Go to Project Settings in Firebase
- Click "Service Accounts"
- Click on link "Manage service account permissions" (this will take you to Google Cloud Console)
- Click "CloudShell" icon on the top menu
Once CloudShell starts, run the following command (Use your bucket address from Firebase where your images are stored)
gsutil cors get gs://your-project.firebasestorage.app
Restart your application and it should work!
If you haven't setup CORS in your firebase console, Follow these steps :
Go to Project Settings in Firebase
Click "Service Accounts"
Click on link "Manage service account permissions" (this will take you to Google Cloud Console)
Click "CloudShell" icon on the top menu
Once CloudShell starts, run the following command (Use your bucket address from Firebase where your images are stored)
-
echo '[{"origin": ["*"],"responseHeader": ["Content-Type"],"method": ["GET", "HEAD"],"maxAgeSeconds": 3600}]' > cors-config.json
Apply the CORS Configuration to Your Storage Bucket
Replace
YOUR_BUCKET_NAME
with your actual bucket name. You can find your bucket name in the Firebase Console under Storage.Copy the bucket name in the format
gs://your-bucket-name
.Execute the following command in the Cloud Shell terminal to apply the CORS configuration:
gsutil cors set cors-config.json gs://YOUR_BUCKET_NAME
Verify the CORS Configuration
- To check if the CORS settings were applied correctly, run the following command:
gsutil cors get gs://YOUR_BUCKET_NAME
https://codingwitht/how-to-view-cloud-images-in-flutter-web-enable-cors/
- To check if the CORS settings were applied correctly, run the following command:
本文标签:
版权声明:本文标题:firebase - Flutter Web not showing images . Giving EncodingError: The source image cannot be decoded - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744979306a2635717.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Image
widget docs say: '''the following image formats are supported: JPEG, PNG, GIF, Animated GIF, WebP, Animated WebP, BMP, and WBMP''' – pskink Commented Mar 6 at 11:34name.png?alt=media
– Zee A Commented Mar 6 at 11:37Image.file
/Image.asset
? – pskink Commented Mar 6 at 11:57