我有一个这样的流的组合列表;
var Ref1 = _firestore
.collectionGroup("Posts")
.where('postID', whereIn: List1)
.snapshots();
var Ref2 = _firestore
.collectionGroup("Posts")
.where('postID', whereIn: List2)
.snapshots();
var Ref3 = _firestore
.collectionGroup("Posts")
.where('postID', whereIn: List3)
.snapshots();
List<Stream<QuerySnapshot>> combineList = [Ref1, Ref2, Ref3];
Run Code Online (Sandbox Code Playgroud)
combineList通过这种方法,我合并了来自;的流。
var totalRef = Rx.combineLatest(
combineList, (list) => (list as Iterable<Iterable>).flattened);
Run Code Online (Sandbox Code Playgroud)
然后我用totalRef里面的StreamBuilder。
StreamBuilder<QuerySnapshot>(
stream: totalRef,
builder:
(BuildContext context, AsyncSnapshot asyncsnapshot) {
if (asyncsnapshot.hasError) {
return Center(
child: Text("Error"),
);
} else {
if (asyncsnapshot.hasData) {
List<DocumentSnapshot> listOfDocumentSnapshot =
asyncsnapshot.data.docs;
return ListView.builder( …Run Code Online (Sandbox Code Playgroud)