我想通过存储在Firebase firestore中的url显示带有索引的图像,我正在获取存储在云存储中的图像,但我不知道如何获得存储在firebase firestore中的url。请帮帮我,因为我还只是个初学者,还在网上学习。图片附在下面。

提前谢谢。
List<String> urls = [];
@override
void initState() {
super.initState();
_getImages();
}这是通过存储在云存储中的urls显示图像的容器。
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);
});
});
}发布于 2021-04-30 03:07:42
将此代码放入getImages()函数中
//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 herehttps://stackoverflow.com/questions/67321843
复制相似问题