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;
}
我无法在文档中添加数据。
这是我在firestore中输入数据的代码。请帮忙,我是新手。
return ref.setData(data);
错误是
返回类型“ Future”不是方法“ getUserDoc”定义的“ Future” .dart(return_of_invalid_type)
答案 0 :(得分:1)
这应该有效:
Future<void> 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.setData({'UID': user.uid});
}