7

I've tried to make a new StreamBuilder inside the builder of my initial stream, and while I don't get any errors, it also doesn't seem like it works. Is this possible to do?

Basically, I'm accessing a root Collection in Firebase. This collection contains two documents, and I need data from each of them, as I am building a DataTable that contains information from both paths.

EDIT: The nested StreamBuilder doesn't work because StreamBuilder must return a widget, so at least I know why it wasn't working. But I still don't have a resolution on what to do.

GroovinChip
  • 339
  • 4
  • 17
  • 1
    You can combine streams in various ways. The `rxdart` package provides a large set of stream transformers for that purpose, the `async` from the Dart team provides a few as well. – Günter Zöchbauer Jun 26 '18 at 03:02
  • You could combine using StreamZip or StreamGroup and with the combined stream you use .asBroadcastStream() – Lingster Jul 05 '19 at 16:19

2 Answers2

1

you can use it like this:

    StreamBuilder(
        stream: firestore.collection("nameofcollection").doc.snapshots(),
        buider: (context, AsyncSnapshot snapshot){
            if(snapshot.hasError) return Text('your error');
                if(snapshot.hasData){  
                    typeList List nameList = [];
                    snapshot.forEach((e){
                        typeObject object = ();
                        object.property1 = e.get('property1Database');
                        object.property2 = e.get('property2Database');
                        nameList.add(object);
                    });
                    //now use the list that will be loaded with the 2 documents
                 }
            }
    );
0

Have you tried using StreamZip? This should help you manage multiple streams. Here's a sample on how it could be used.

import 'package:async/async.dart';

Stream<DocumentSnapshot> stream1 = firestore.document('/path1').snapshots();
Stream<DocumentSnapshot> stream2 = firestore.document('/path2').snapshots();
StreamZip bothStreams = StreamZip([stream1, stream2]);

// To use stream
bothStreams.listen((snaps) {
 DocumentSnapshot snapshot1 = snaps[0];
 DocumentSnapshot snapshot2 = snaps[1];

 // ...
});

Do you have a minimal repro of what you're trying to implement along with the steps to replicate the behavior? I also need how the data you're trying to access looks like. This will help me visualize how you're trying to run multiple streams for Firestore (I assumed since Collection was mentioned).

Omatt
  • 8,564
  • 2
  • 42
  • 144