小部件库捕获的异常 - Flutter

Exception caught by widgets library - Flutter

正如我在标题中提到的,我收到了这个错误:

Exception caught by widgets library 
Closure call with mismatched arguments: function '[]'
Receiver: Closure: () => Map<String, dynamic> from Function 'data':.
Tried calling: []("imageURL")
Found: []() => Map<String, dynamic>

我一直在尝试使用它从 firestore 获取数据并将其显示在我的应用程序页面上。但是我无法从 collection 获取数据,尤其是图像。我从 youtube 引用了这个教程。即使我做了所有相同的事情,但我无法处理它。也许是公元前的版本。如果你能帮助我,我会很高兴。

class _HomeState extends State<Home> {
  PostService postService = new PostService();
  Stream postStream;


  //Stream postsStream;
  Widget postsList() {
    return SingleChildScrollView(
      child: postStream != null
        ? Column(
          children: <Widget>[
         StreamBuilder(
           //stream: postStream,
           stream: postStream,
           builder: (context, snapshot)
           {
             if(snapshot.data == null) return CircularProgressIndicator();
        
             return ListView.builder(
                 padding: EdgeInsets.symmetric(horizontal:16.0),
                 itemCount: snapshot.data.docs.length,
                 shrinkWrap: true,
                 itemBuilder: (context, index) {
                   return PostTile(
                     imgUrl: snapshot.data.docs[index].data['imageURL'],
                     title: snapshot.data.docs[index].data['postTitle'],
                     desc: snapshot.data.docs[index].data['postDesc'],
                     city: snapshot.data.docs[index].data['cityName'],

                   );
                 });
           }),
        ],
        ): Container(
    alignment: Alignment.center,
    child: CircularProgressIndicator(),
    ),
    );
  }

  @override
  void initState() {

    postService.getPostData().then((result) {
        setState(() {
        postStream = result;
      });
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text('Ana Sayfa'),
        backgroundColor: Colors.amber,
        elevation: 0.0,
        actions: <Widget>[
          FlatButton.icon(
            icon: Icon(Icons.group_rounded),
            label: Text(''),
            onPressed: () {
              Navigator.push(
                  context,
                  MaterialPageRoute(
                      builder: (context) => KullaniciSayfasi()));
            },
          ),
        ],
      ),
      body: postsList(),
      floatingActionButton: Container(
        padding: EdgeInsets.symmetric(vertical: 10.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
     

 children: <Widget>[
        FloatingActionButton(
          onPressed: () {
            //Ekleme butonuna basıldığında
            Navigator.push(context,
                MaterialPageRoute(builder: (context) => CreatePost()));
          },
          child: Icon(Icons.add),
        )
      ],
    ),
  ),
);

} }

post 服务代码

import 'package:cloud_firestore/cloud_firestore.dart';


class PostService{

  Future<void> addData(postData) async{
  FirebaseFirestore.instance.collection("posts").add(postData).catchError((e){
     print(e);
    });
  }

  getPostData() async{

    return await FirebaseFirestore.instance.collection("posts").snapshots();
  }
}

Firebase 插件发生了重大变化,许多事情都发生了变化。例如,我看到你在做 snapshot.data.docs[index].data['imageURL'] 这已更改为 snapshot.data.docs[index].data()['imageURL']。请检查文档以获取更新的 API 参考资料