QuerySnapshot querySnapshot = await _collectionRef
.limit(1)
.orderBy('date')
.getDocuments();
var list = querySnapshot.documents;
querySnapshot.documents.map((document) {
print('Document : $document'); // not printing anything.
});
if(list.length > 0) {
print('ID : ${list[0].documentID}'); // not working
}
这是我试过的确切代码...
代码中有什么错误?
最佳答案
根据API documentation , DocumentSnapshot有一个 documentId属性(property),所以我希望这能奏效:
querySnapshot.documents[0].documentID
关于flutter - 如何从文档快照中获取 Firestore 文档 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55113849/