android - Flutter / FireStore: how to display an image from Firestore in Flutter?
问题描述
I want to put some images that I use in my app to Firestore, and display them from there, rather than having them as assets, bundled in my app.
In order to do this, I came up with the following solution: for the item I want to display an image, I created a Firebase document, where I have a field that stores the name of the file that stores the corresponding picture:
document
- name
- description
- imageName
Then, I uploaded an image to FireStore with the same name.
When I want to display the image, I can successfully get the document via StreamBuilder, and extract the imageName property.
I also created the necessary FireStore references:
FirebaseStorage storage = new FirebaseStorage(
storageBucket: 'gs://osszefogasaszanhuzokert.appspot.com/'
);
StorageReference imageLink = storage.ref().child('giftShopItems').child(documentSnapshot['imageName']);
However, I can't seem to pass it to an Image.network()
widget.
Is it possible to display an image the way I'd like to, or should I use a different Image provider?
解决方案
您需要.getDownloadURL()
从 StorageReferenceimageLink
获取存储 URL 链接:
final imageUrl = await imageLink.getDownloadUrl();
Image.network(imageUrl.toString());
推荐阅读
- android - Recyclerview 移至屏幕外可见性
- python - Boto3 Python Lambda自定义返回错误
- java - 如何从 XML 中获取哈希以登录 java
- java - Java 套接字服务器,在集群服务器上
- vb.net - 如何创建仅适用于支持特定接口的类的泛型类?
- python - 如何在 Google Colab 上安装 nvidia apex
- angular - Angular 2+ Universal 页面未在服务器上呈现
- python - 读取 CSV 并调用第三方 API 性能问题
- c# - 无法使用 [] 将索引应用于“System.Collections.Generic.HashSet”类型的表达式
' - python - 未加权图中的路径:从源头到源头的最短行程,施加一个点