在flutter中从Firebase检索特定的用户数据 [英] Retrieve specific user data from firebase in flutter

查看:48
本文介绍了在flutter中从Firebase检索特定的用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

集合名称是我要为特定用户检索数据的特定用户ID.我怎样才能做到这一点.这是我的数据库 1 的屏幕截图我尝试了这段代码,但是由于数组,它只返回第一个集合

the collection name is the specific user id i want to retrieve data for the specific user. how can i do that. this is the screen shot of my database 1 i tried this code but it return only the 1st collection because of the array


StreamBuilder(
       stream: Firestore.instance.collection("/userdata").snapshots(),
       builder: (context, snapshot) {
     gnickname = snapshot.data.documents[0]["Nickname"];
     gphotourl = snapshot.data.documents[0]["photoURL"];})    


推荐答案

要获取基于uid使用的特定记录,在您的情况下,以下代码:

To get a specific record based on the uid use, in your case, the following code:

var userData = Firestore.instance.collection("/userdata").document("uid").get();

userData 是一个 DocumentSnapshot ,因此请使用 userData.data 对象获取键/值对.

userData is a DocumentSnapshot so use userData.data object to get the key/value pairs.

这篇关于在flutter中从Firebase检索特定的用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆