【发布时间】:2023-02-08 23:13:59
【问题描述】:
我想在我的 flutter 应用程序中显示当前用户数据。但它在屏幕上打印“未找到数据”。 这是我的数据库数据
该错误也发生了错误
我的安全规则
这是我的代码
Container(
child: StreamBuilder(
stream: FirebaseFirestore.instance.collection("user3").where("id",isEqualTo:FirebaseAuth.instance.currentUser!.uid).snapshots(),
builder: (BuildContext context,AsyncSnapshot<QuerySnapshot> snapshot){
if(!snapshot.hasData){
return Text("Loading please wait........");
}
if (snapshot.hasData && snapshot.data!.docs.length > 0) {
DocumentSnapshot userData = snapshot.data!.docs[0];
// Build the widget using the userData
} else {
return Center(child: Text("No data found"));
}
return Container();
},
),
),
【问题讨论】:
-
您确定此时您的代码中有当前用户登录吗?从您的错误消息来看,它看起来不像。检查您的“FirebaseAuth.instance.currentUser”是否已登录。最近几天我一直在处理类似的代码,您可以在“where(”id”, isEualTo ..”) 之后执行类似的操作检查那是否是你有错误的地方:snapshot, error in if error != nil { print(error!.localizedDescription) return }
-
是的,当前用户已登录。而且当我想在控制台中打印数据时,它显示空数组。你能通过具体的代码解决错误吗?
-
请不要发布您的代码的屏幕截图,或其他文本内容,例如错误消息和安全规则。而是发布实际文本,并使用 Stack Overflow 的格式化工具对其进行标记。另见:Why not upload images of code/errors when asking a question?
标签: flutter firebase dart google-cloud-firestore stream-builder