首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >flutter firebase firestore:如何获取存储在数组firestore中的图像?

flutter firebase firestore:如何获取存储在数组firestore中的图像?
EN

Stack Overflow用户
提问于 2021-04-30 00:54:41
回答 1查看 527关注 0票数 1

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

提前谢谢。

代码语言:javascript
复制
List<String> urls = [];

  @override
  void initState() {
  super.initState();

 _getImages();
 
}

这是通过存储在云存储中的urls显示图像的容器。

代码语言:javascript
复制
                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),

                        )
                      ],
                    ),
                ),

这是我获取存储在云存储中的图像的方法。

代码语言:javascript
复制
_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);
  });
});

 }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-30 03:07:42

将此代码放入getImages()函数中

代码语言:javascript
复制
//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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67321843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档