[英](Flutter) How to retrieve Firebase Storage images in a Streambuilder with the paths stored in Firestore
[英]flutter firebase firestore: How to get images stored in array firestore?
我想通过存储在 Firebase 火库中的 url 显示带有索引的图像,我正在获取存储在云存储中的图像,但我不知道如何获取 url 存储在数组中的 ZBF12E1515C213C7D8C0352F1 中请帮助我,因为我只是一个初学者并通过互联网学习。 图片附在下面。 提前致谢。
List<String> urls = [];
@override
void initState() {
super.initState();
_getImages();
}
这是通过存储在云存储中的 url 显示图像的容器。
Container(
height: 160.0,
padding: EdgeInsets.symmetric(vertical: 15.0,horizontal: 15.0),
child: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: <Widget>[
SliverPadding(
padding: const EdgeInsets.all(10),
sliver:
_buildContent(urls),
)
],
),
),
这是我获取存储在云存储中的图像的方法。
_getImages() async {
ListResult _result = await _stoarge.ref().child("images").list(ListOptions(maxResults: 10));
_result.items.forEach((_ref) async {
String _u = await _ref.getDownloadURL();
urls.add(_u);
setState(() {
print(urls.length);
print(urls);
});
});
}
把它放在你的getImages()
function
//First, you must retrieve your document, like this:
DocumentSnapshot firebaseDoc = await FirebaseFirestore.instance.collection('users').doc('yourDocumentId').get();
//then you need to extract your list, which is in the 'images' field, you can do so like this:
List<String> imagesList = firebaseDoc.data()['images'];
//Now, you have a list, containing the URLs you want.
print(imagesList[0]); //should print the first URL, you can take it from here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.