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


I am getting this error when trying to fetch user posts from Firestore with the StreamBuilder.

Widget build(BuildContext context) {
return Column(
  children: <Widget>[
child: StreamBuilder(
      stream: postRef
          arrayContains: FirebaseAuth.instance.currentUser.uid)
          .orderBy('timestamp', descending: true)
      builder: (context, snapshot) {
if (snapshot.hasData) {
        return ListView.separated(
          itemCount: snapshot.data.docs.length,
          itemBuilder: (context, index) {
            Review posts = Review.fromJson(snapshot.data);
            return Padding(
              padding: const EdgeInsets.only(bottom: 10.0),
              child: Posts(post: posts),
          separatorBuilder: (context, index) {
            return Column(
              children: [
                if (index % 3 == 0 && index != 0)
                  AdWidget(ad: ad)
} else if (snapshot.hasError) {
  return Center(
    child:  Text(Languages.of(context).errorOcc),
} else {
  return  Container();}},))],);//)]);

I tried casting the review posts as Map<String, dynamic>, but then the child: Posts(post: posts) gives the same error. I tried suggestions from the answers but that is a FutureBuilder, not StreamBuilder. I am new to this, so still very confused. Help appreciated very much!


Use data() on docs to access individual documents with the help of index:


Answered By – Tirth Patel

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *