我对这两者之间的区别有点困惑。我的理解是这getDocuments
是一种Future,似乎根据查询获取整个文档。snapshots
另一方面,while是一种 Stream 类型,如果我错了,请纠正我,我认为它代表查询的结果?我需要对这个问题进行更具体的解释。我将包含一些代码片段作为示例以进行更多说明
获取文档()
getUserById(String userId) async {
return await _firestore.collection("users").where("userId", isEqualTo: userId).getDocuments();
}
Run Code Online (Sandbox Code Playgroud)
快照()
getUserById(String userId) async {
return await _firestore.collection("users").where("userId", isEqualTo: userId).snapshots();
}
Run Code Online (Sandbox Code Playgroud)
那么有什么区别呢?