【发布时间】:2022-06-16 15:41:35
【问题描述】:
如何为 Streambuilder 中返回的每个项目输出复选框,并记录该信息以便以后对其进行处理?我不知道将输出多少项目,所以我不知道应该使用多少变量来检查复选框的状态。我还附上了一个基本的 UI 来勾勒出我希望 streambuilder 看起来和记录的内容。 注意:我目前处于无状态小部件中,但是,如有必要,我可以将其更改为有状态
StreamBulder 的代码
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection("children")
.where("parentUID",
isEqualTo: FirebaseAuth
.instance.currentUser!.uid)
.orderBy('timestamp',
descending: true)
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot>
snapshot) {
if (snapshot.hasError) {
return const Text(
'Something went wrong');
}
if (snapshot.connectionState ==
ConnectionState.waiting) {
return const Text("Loading");
}
return Column(
children: snapshot.data!.docs.map(
(DocumentSnapshot document) {
Map<String, dynamic> data =
document.data()!
as Map<String, dynamic>;
return Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
/*Output a checkbox for every result returned and name its title 'data['childUserName']'. Then, I want to be able to record the responses of those checkboxes and save them when I run a function.*/
],
);
},
).toList(),
);
},
),
【问题讨论】:
标签: flutter