【发布时间】:2021-06-28 18:09:51
【问题描述】:
正如您在我的代码中看到的,我想将密钥(ListTile 的 docID)导出到函数 onPressedNegativ。有了它,我希望能够编辑我的 firestore 数据库的数据。其背后的确切想法是将字段 ergebnis 更新为另一个值,即在我的 ListTile 的前导可见不同的图标。
所以问题是,我怎样才能导出 ListTile 的正确 docID,在该按钮上我按下了将我带到 onPressedNegativ 功能的按钮?
感谢您的任何帮助。
void onPressedNegativ() {
// update something in firebase
// how can I get the actual docID?
}
Widget _buildList(QuerySnapshot snapshot) {
return ListView.separated(
padding: EdgeInsets.all(20),
separatorBuilder: (context, index) => Container(
height: 10,
),
itemCount: snapshot.docs.length,
itemBuilder: (context, index) {
final doc = snapshot.docs[index];
return ListTile(
key: Key(doc.id),
leading: (doc["ergebnis"] == "Ausstehend")
? Icon(Icons.schedule)
: Icon(Icons.check),
title: Text(
doc["nachname"] + ", " + doc["vorname"],
),
subtitle: Text(doc["adresse"] +
" / " +
doc["Geburtsdatum"] +
" / " +
doc["telefon"]),
trailing: Wrap(
spacing: 12,
children: [
OutlineButton.icon(
borderSide: BorderSide(color: Colors.red),
onPressed: onPressedNegativ,
icon: Icon(
Icons.cancel_rounded,
color: Colors.red,
),
label: Text(
"Test positiv",
style: TextStyle(color: Colors.red),
),
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
),
OutlineButton.icon(
borderSide: BorderSide(color: Colors.green),
onPressed: () {},
icon: Icon(
Icons.check_box_rounded,
color: Colors.green,
),
label: Text(
"Test negativ",
style: TextStyle(color: Colors.green),
),
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
)
],
),
);
},
);
}
}
【问题讨论】:
标签: firebase flutter listview web