【发布时间】:2021-08-27 14:03:35
【问题描述】:
【问题讨论】:
-
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
【问题讨论】:
为您的用户集合创建一个变量
final CollectionReference _usersCollection =
FirebaseFirestore.instance.collection("users");
根据userId值查询用户文档快照
final QuerySnapshot<Object?> usersQuery = await _usersCollection.where("uid",isEqualTo: userId).limit(1).get();
您可以从文档快照中获取地图数据
if(usersQuery.length>0) {
final Map<String, dynamic> userData =
usersQuery.docs[0].data() as Map<String, dynamic>;
return userData['userType']; // you can use the data as you wish here am returning it
}
// else do something when the data isn't available
【讨论】:
final _firestoreInstance = FirebaseFirestore.instance;
// returns a list of user documents
final res = await _firestoreInstance.collection("user_type").get();
// returns the first user_type instance of the list
final firstUser = res.docs.first.data();
return firstUser['uid'];
【讨论】: