google-cloud-firestore - Flutter webapp:Snapshort返回一个空值
问题描述
我是新来的,一直在尝试从 firebase 中检索数据并显示,但它的快照为空。我已经解决了其他用户提出的类似问题,但没有任何效果。
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: BackButton(
color: Colors.white,
),
bottomOpacity: 1.0,
backgroundColor: mucolor1,
title: Text(
"Customer receipt ",
style: TextStyle(color: Colors.white, fontSize: 12),
),
),
body: Stack(
clipBehavior: Clip.none,
alignment: Alignment.topCenter,
children: [
Container(
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection("users")
.doc(tableNo)
.collection("order")
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting)
return new Center(child: new CircularProgressIndicator());
if(snapshot.data!=null){
return Container(
margin: EdgeInsets.fromLTRB(20, 100, 20, 0),
child: ListView(
children: snapshot.data.docs.map((document) {
return Container(
color: Colors.white54,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Card(
elevation: 0,
child: Container(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: [
Text("Tsh " +
document.get("price").toString() +
"/="),
Text(document.get("qty").toString()),
Text(document.get("title")),
],
),
),
)
],
));
}).toList(),
),
);
}else {
return Positioned(
top: 80,
child: Center(
child: Container(
margin: EdgeInsets.fromLTRB(20, 10, 20, 0),
child: Text("No data"))),
);
}
},
),
),
Positioned(
top: 10,
child: Center(
child: Container(
margin: EdgeInsets.fromLTRB(20, 10, 20, 0),
child: Text("Your Order"))),
),
Positioned(
top: 50,
child: Container(
margin: EdgeInsets.fromLTRB(20, 10, 20, 0),
child: Text(
"Total Cost Tsh " + grandTotal + "/=",
style:
TextStyle(color: mucolor2, fontWeight: FontWeight.bold),
))),
],
),
);
} }
这是我的数据库结构:
我需要你的帮助。我一直在努力解决这个问题一个月了。
解决方案
您的users
文件是空的;这意味着实际上没有文件代替它。
在这种情况下,您应使用collectionGroup('order')
- https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query
推荐阅读
- python - 用户警告:“会话”cookie 太大:值为 14773751 字节,但标头需要 26 个额外字节
- javascript - 当第三个人加入聊天时,webrtc 视频聊天不起作用
- jupyter-notebook - 使用 folium.Maps 时获取“TypeError:必须是实数,而不是 str”
- sql - 使用 WHERE 子句条件的 ALTER TABLE
- typescript - 如何在测试中使用 react-testing-library 和 Next.js 触发重定向
- amazon-ses - AWS SES 中的电子邮件数量突然激增
- strava - Strava api 导出活动的 GPX 文件
- windows - 调试器如何跟踪堆栈?
- excel - VBA 宏在 2 张工作表上的 2 列中查找部分匹配并将值从工作表 2 复制到工作表 1
- amazon-cognito - 如何从 Alexa 技能调用安全 API?