如何在 flutter firestore 中获取用户 ID [英] How get user id in flutter firestore
本文介绍了如何在 flutter firestore 中获取用户 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 flutter 新手,不知道如何在 firestore 中的特定文档(userId)中进行写入.
I'm new in flutter and I don't know how to write in a particular document(userId) in firestore.
我希望我的数据库是这样的:用户(集合)|-> 用户 ID|->姓名:里奇
I want my database is like: users(collection) |-> userId |->name : Richie
这是我的尝试:
Future<FirebaseUser> user =FirebaseAuth.instance.currentUser();
DocumentReference ref =Firestore.instance.collection('users').document(user.uid);
请帮忙
推荐答案
您需要等待获得 FirebaseUser
才能访问 id
.我在下面创建了一个简单的函数来为您演示这一点.
You need to await to get the FirebaseUser
before you can access the id
.
I created a simple function below demonstrating this for you.
Future<DocumentReference> getUserDoc() async {
final FirebaseAuth _auth = FirebaseAuth.instance;
final Firestore _firestore = Firestore.instance;
FirebaseUser user = await _auth.currentUser();
DocumentReference ref = _firestore.collection('users').document(user.uid);
return ref;
}
这篇关于如何在 flutter firestore 中获取用户 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文