type ‘_JsonQuerySnapshot’ error occured while using firestore QuerySnapShots

Issue

This Content is from Stack Overflow. Question asked by MooNChilD Song

I think I got used to using DocumentSnapshot, without using any ordering or filtering.

Now I am making a query streamer using the code :

Stream<QuerySnapshot> postStream_left = FirebaseFirestore.instance.collection('post')
.where('topic',isEqualTo: received_id)
.where('side',isEqualTo:'left')
.orderBy('like')
.snapshots();

Stream<QuerySnapshot> postStream_right = FirebaseFirestore.instance.collection('post')
.where('topic',isEqualTo: received_id)
.where('side',isEqualTo:'right')
.orderBy('like').snapshots();

return StreamBuilder(stream:postStream_left,builder: (context,snapshot_l)
        {
          if(!snapshot_l.hasData){
            return CircularProgressIndicator();
          }
          return StreamBuilder(stream:postStream_right,builder: (context,snapshot_r)
          {
            if(!snapshot_r.hasData){
              return CircularProgressIndicator();
            }
            final documents_l = snapshot_l.data as Map<String,dynamic>;     // Here is where I am stuck
            final documents_r = snapshot_r.data as Map<String,dynamic>;
            print('afepwmcakodepwxa.ofpe,[wambotpmwa');
            print(documents_l);
            print(documents_r);
            return CircularProgressIndicator();
          }
          );
        }
        );

What I want to do is show the data of postStream_left and postStream_right in two listview at the same time. However I donot know how to parse the data of each QuerySnapshot, since they did not work with code that works for Documentsnapshot.

type '_JsonQuerySnapshot' is not a subtype of type 'Map<String, dynamic>' in type cast

Here is the error I got but flutter does not tell me how I should cast the data.

Please tell me what to do and thank you very much.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?