简体   繁体   English

Flutter / FireStore:如何在Flutter中显示Firestore中的图像?

[英]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. 我想将我在应用程序中使用的某些图像放到Firestore中,然后从那里显示它们,而不是将它们作为资产捆绑在我的应用程序中。

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: 为此,我想出了以下解决方案:对于要显示图像的项目,我创建了一个Firebase文档,其中有一个字段,用于存储存储相应图片的文件的名称:

document
- name
- description
- imageName

Then, I uploaded an image to FireStore with the same name. 然后,我以相同的名称将图像上传到FireStore。

When I want to display the image, I can successfully get the document via StreamBuilder, and extract the imageName property. 当我想显示图像时,我可以通过StreamBuilder成功获取文档,并提取imageName属性。

I also created the necessary FireStore references: 我还创建了必要的FireStore参考:

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. 但是,我似乎无法将其传递给Image.network()小部件。

Is it possible to display an image the way I'd like to, or should I use a different Image provider? 是否可以按照我想要的方式显示图像,还是应该使用其他图像提供程序?

You need the .getDownloadURL() from the StorageReference imageLink to get the storage URL link: 您需要来自StorageReference imageLink.getDownloadURL()来获取存储URL链接:

final imageUrl = await imageLink.getDownloadUrl();
Image.network(imageUrl.toString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 flutter 中显示来自 Firestore 的特定文档详细信息 - How to display a specif document detail from firestore in flutter 如何使用Flutter将整数存储到Firestore - How to store integers to Firestore with Flutter 如何从Firestore的URL显示图像 - How to display image from URL from Firestore Flutter Firebase:如何从 Firebase 调用显示名称和 UID 验证然后使用这些值并保存在 Cloud Firestore - Flutter Firebase : How to call Display Name and UID from Firebase Auth then use those values and save in Cloud Firestore 如何在 Flutter 中使用 FutureBuilder 显示来自 firestore 数据库的当前用户数据? - How to display the current user data from firestore database using FutureBuilder in Flutter? Flutter 如何使用 firestore 从 streambuilder 进行分页(延迟加载) - Flutter How to make a pagination from streambuilder with firestore (lazy loading) 如何缩小来自 Flutter Firestore 的传入数据的字符? - How to Shrink Characters of Incoming Data from Flutter Firestore? Flutter:我如何从列表中的 Firestore 获取数据<String> ? - Flutter : how i get data from firestore in List<String>? 如何从 firestore 获取数据并将其设置为 Flutter TextFormField - How to fetch data from firestore and set it to Flutter TextFormField Flutter:Firestore 组件不存在 - Flutter: Firestore component is not present
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM