flutter - 未为类“地图”定义运算符“[]”功能()'
问题描述
我正在尝试从 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'],
^
请让我带着这个错误离开这里
解决方案
我猜测该链中的某处(如数据)是一个函数,需要通过添加()来调用。使用您的 IDE 来验证数据的类型。
推荐阅读
- c# - 更改 BlazorApp 中的默认图标
- regex - 正则表达式递归捕获的字符串
- field - 我如何编写代码来执行“当我在选项窗口中单击取消时,该字段将隐藏。”
- android - Sharedprefrences 不保存?
- google-cloud-platform - 即使第二个 SSL 证书设置为 Google Cloud Platform 负载平衡器,它也会从目标中消失
- c# - 我有 3 个文本框,分别代表日、月和年。由此需要计算日期
- firebase - 单个云函数调用 100+ 本地函数
- react-redux - 为什么会自动创建一个状态?(还原)
- mysql - 拆分值并循环它们
- java - 在一段时间内使用 kafka-streams 处理和检查事件