[英]How to get a single user data from firestore without future builder in flutter
I have this in my Auth Controller我在我的 Auth Controller 中有这个
Future<Member?> readLoggedMemberonly() async {
final User? user = Auth().currentUser;
final mid = user?.uid;
final docMember =
FirebaseFirestore.instance.collection('users').doc(mid.toString());
final snapshot = await docMember.get();
if (snapshot.exists) {
return Member.fromJson(snapshot.data()!);
} else {
return null;
}
}
and in my View I have this在我看来我有这个
final mem = Auth().readLoggedMemberonly;
Now I want to access users data like name现在我想访问名称等用户数据
I tried with我试过了
child: Text(mem?.name), //name was declared in the model and it exits in the firestore users document
But got this error但是得到了这个错误
this after removing const from Drawer从Drawer中删除const后的 this
final mem = Auth().readLoggedMemberonly;
if you want to call a function you have to add brackets如果你想调用 function 你必须添加括号
final mem = Auth().readLoggedMemberonly();
Then, its future, so probably you want to await for it然后,它的未来,所以可能你想等待它
final mem = await Auth().readLoggedMemberonly();
then you can use your value那么你可以使用你的价值
Text(mem?.name ?? '');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.