我知道这可能看起来很明显,但我就是找不到办法做到这一点..
我正在尝试从 firebase 查询中获取单个文档。当我说单个文档时,我的意思不是流。
到目前为止,我的方法是:
MyClass getDocument(String myQueryString) {
return Firestore.instance.collection('myCollection').where("someField", isEqualTo: myQueryString) //This will almost certainly return only one document
.snapshots().listen(
(querySnapshot) => _myClassFromSnapshot(querySnapshot.documents[0])
);
}
但是,我收到了错误A value of type 'StreamSubscription<QuerySnapshot>' can't be returned from method 'getDocument' because it has a return type of 'MyClass'.
谢谢!