0

So, i want to write query like this

... where from = x or to =x 

I can't find any documentation about using where condition. So, i using StreamZip

@override
  void initState() {
    getEmail();
    stream1 = databaseReference
        .collection("userChat")
        .where("from", isEqualTo: userId)
        .orderBy("messageDate", descending: true)
        .snapshots();
    stream2 = databaseReference
        .collection("userChat")
        .where('to', isEqualTo: userId)
        .orderBy("messageDate", descending: true)
        .snapshots();
  }

and here is my StreamBuilder

                    StreamBuilder(
                        stream: StreamZip([stream1, stream2]),
                        builder: (context, snapshot) {
                          print(snapshot.data.documents);
                          switch (snapshot.connectionState) {
                            case ConnectionState.none:
                            case ConnectionState.waiting:
                              return Center(
                                child: CircularProgressIndicator(),
                              );
                            default:
                              return new Flexible(
                                child: new ListView.builder(
                                  controller: _scrollController,
                                  padding: new EdgeInsets.all(8.0),
                                  reverse: false,
                                  itemBuilder: (context, index) {
                                    print("Time to show data");
                                    List rev = snapshot
                                        .data.documents.reversed
                                        .toList();
                                    MessageFromCloud messageFromCloud =
                                        MessageFromCloud.fromSnapshot(
                                            rev[index]);
                                    return new ChatMessage(
                                        data: messageFromCloud,
                                        userFullname: userFullname,
                                        userId: userId,
                                        roomId: documentId);
                                  },
                                  itemCount: (messagesCloud != null)
                                      ? messagesCloud.length
                                      : 0,
                                ),
                              );
                          }
                        }),

When i run it, i get this error

Class 'List' has no instance getter 'documents'. Receiver: _List len:2 Tried calling: documents

Did i miss something?

Boby
  • 1,131
  • 3
  • 20
  • 52

1 Answers1

2

StreamZip - emits lists of collected values from each input stream

It means that your snapshot.data is a List.

Would suggest checking out this answer: Combine streams from Firestore in flutter

Adelina
  • 10,915
  • 1
  • 38
  • 46