类型“_JsonQuerySnapshot”不是 StreamBuilder 中类型 'Map<String, dynamic>' 的子类型

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

我在尝试使用 StreamBuilder 从 Firestore 中获取用户 post 时遇到此错误。

@override
Widget build(BuildContext context) {
return Column(
  children: <Widget>[
Expanded(
child: StreamBuilder(
      stream: postRef
          .where("bookmarks",
          arrayContains: FirebaseAuth.instance.currentUser.uid)
          .orderBy('timestamp', descending: true)
          .snapshots(),
      builder: (context, snapshot) {
if (snapshot.hasData) {
        return ListView.separated(
          itemCount: snapshot.data.docs.length,
          itemBuilder: (context, index) {
            internetChecker(context);
            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();}},))],);//)]);
}

我尝试将评论 posts 转换为 Map,但 child: Posts(post: posts) 给出了同样的错误。我尝试了 answers 的建议,但那是 FutureBuilder,而不是 StreamBuilder。我对此很陌生,所以仍然很困惑。非常感谢帮助!

docs 上使用 data() 以在 index 的帮助下访问个人文档:

Review.fromJson(snapshot.data.docs[index]!.data()!)

改变这个:

Review posts = Review.fromJson(snapshot.data);

为此:

Review posts = Review.fromJson(snapshot.data.docs[index]);