firebase - 如何修改代码以使Stream Builder具有Stream <dynamic>类型的流?

标签 firebase flutter dart google-cloud-firestore firebase-authentication

在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/

相关文章:

javascript - Firebase 存储 : string does not match format base64: invalid character found. 仅当调试关闭时

flutter - 在Mockito中使用任何或任何命名匹配器来嵌套值

sqlite - Flutter:为什么此函数内的方法无法访问数据库变量?

flutter - Visual Studio Code Flutter 格式不适用于我的缩进空间值

ios - 无法配置 Firebase InstanceID

ios - 一旦我注销并登录,ViewDidLoad 状态似乎不会刷新

ios - 与名为 com.apple.commcenter.coretelephony.xpc 的服务的连接已失效

android - MANAGE_EXTERNAL_STORAGE 权限

firebase - Dart null与Null

android - 如何使用多个 View 在Flutter中填充Listview