功能()',flutter,dart"/>

首页 > 解决方案 > 未为类“地图”定义运算符“[]”功能()'

问题描述

我正在尝试从 firebase 加载这些数据:

Widget BlogList() {
return Container(
  child: Column(
    children: [
      blogSnapshot != null ? ListView.builder(
        itemCount: blogSnapshot.docs.length,
        shrinkWrap: true,
        itemBuilder: (context, index){
          return BlogTile(
            authorName: blogSnapshot.docs[index].data['authorName'],
            title: blogSnapshot.docs[index].data['title'],
            description: blogSnapshot.docs[index].data['description'],
            imgUrl: blogSnapshot.docs[index].data['imgUrl'],
          );
        },
      ): Container(
        alignment: Alignment.center,
        child: CircularProgressIndicator(),)
    ],
  ),
);

}

但我收到此错误:

    Error: The operator '[]' isn't defined for the class 'Map<String, dynamic> Function()'.
 - 'Map' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '[]' operator.
                authorName: blogSnapshot.docs[index].data['authorName'],
                                                         ^

请让我带着这个错误离开这里

标签: flutterdart

解决方案


我猜测该链中的某处(如数据)是一个函数,需要通过添加()来调用。使用您的 IDE 来验证数据的类型。


推荐阅读