Merge Firestore streams using rxDart

纵然是瞬间 提交于 2019-12-02 14:53:14

问题


I am trying to merge two streams from Firestore into one stream using RxDart, but it's only returning results of one stream

Stream getData() {
    Stream stream1 = Firestore.instance.collection('test').where('type', isEqualTo: 'type1').snapshots();
    Stream stream2 = Firestore.instance.collection('test').where('type', isEqualTo: 'type2').snapshots();
    return Observable.merge(([stream2, stream1]));
}

回答1:


Depending on your use case, you might not need RxDart to do this. If you just want to have two Firestore streams merged to one Dart Stream you can use StreamZip from the dart:async package.

import 'dart:async';     

Stream<List<QuerySnapshot>> getData() {
  Stream stream1 = Firestore.instance.collection('test').where('type', isEqualTo: 'type1').snapshots();
  Stream stream2 = Firestore.instance.collection('test').where('type', isEqualTo: 'type2').snapshots();
  return StreamZip([stream1, stream2]).asBroadcastStream();
}


来源:https://stackoverflow.com/questions/52238875/merge-firestore-streams-using-rxdart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!