在Stream Builder内部,它要求我放入Stream<builder>
,否则会引发错误,type 'Future<dynamic>' is not a subtype of type 'Stream<dynamic>'
现在,由于我关注了this answer,因此我不得不像这样对流进行编码,
getGroupsOfUser() async {
String _userID = await _getUID();
DocumentSnapshot userInfo = await userCollection.document(_userID).get();
return groupCollection.where(FieldPath.documentId, whereIn: userInfo.data['groups']).snapshots();
}
现在我知道也许我可以克服使用异步的问题,我可以修复它,但是我需要获取uid和作为异步函数的组的数组,并且我不能真正将它们分配为变量,否则会收到错误only static members can be accessed in initializers
拜托,有人,帮帮我,我在这方面是个初学者。
最佳答案
getGroupsOfUser()
应该返回Stream
,因为snapshots()
返回Stream
。因此,您需要执行以下操作:
Stream<QuerySnapshot> getGroupsOfUser() async* {
String _userID = await _getUID();
DocumentSnapshot userInfo = await userCollection.document(_userID).get();
yield* groupCollection.where(FieldPath.documentId, whereIn: userInfo.data['groups']).snapshots();
}
由于需要返回流,因此需要使用async*
并使用yield*
关键字返回。
关于firebase - 如何修改代码以使Stream Builder具有Stream <dynamic>类型的流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63219893/