yok*_*una 0 stream dart firebase flutter rxdart
我试图使用RxDart将Firestore中的两个流合并到一个流中,但它只返回一个流的结果
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]));
}
Run Code Online (Sandbox Code Playgroud)
根据您的使用情况,您可能不需要RxDart来执行此操作.如果您只想将两个Firestore流合并到一个Dart Stream,则可以StreamZip从dart:async包中使用.
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();
}
Run Code Online (Sandbox Code Playgroud)