M.A*_*Ali 1 firebase flutter google-cloud-firestore
调用setData时如何获取新创建的文档id
Future<void> createCommitment() async {
await widget._firestore
.collection('skills')
.document(widget.skillID)
.collection("commitment")
.document()
.setData({
'bite_id': widget.biteId,
'start_date': widget.startDate,
'frequnecy': 3
});
}
Run Code Online (Sandbox Code Playgroud)
当前实现返回 void
不要使用空的document()or setData,而是像这样seData使用add:
Future<void> createCommitment() async {
DocumentReference docRef = await widget._firestore
.collection('skills')
.document(widget.skillID)
.collection("commitment")
.add({
'bite_id': widget.biteId,
'start_date': widget.startDate,
'frequnecy': 3,
});
//Here you have the autogenerated ID :
print("ID : ${docRef.documentID}");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1172 次 |
| 最近记录: |