flutter - 类没有实例方法`call`
问题描述
NoSuchMethodError
我在我的代码中收到以下内容:
I/flutter ( 6579): The following NoSuchMethodError was thrown building:
I/flutter ( 6579): Class 'List<DocumentSnapshot>' has no instance method 'call'.
I/flutter ( 6579): Receiver: Instance(length:2) of '_GrowableList'
I/flutter ( 6579): Tried calling: call(0)
这是错误行:
return RepTile(RepData.fromDocument(snapshot.data.documents(index)));
解决方案
这里的问题是你使用括号()
来访问你的元素List
,它试图call
在你的对象上调用,但由于你的对象不是函数,这会引发错误。
但是,List
使用方括号[]
来访问给定索引处的对象。
这意味着它很容易解决,只需用方括号替换括号:
return RepTile(RepData.fromDocument(snapshot.data.documents[index]));
推荐阅读
- r - 由 combn 函数创建的小标题的行积和差异
- python - 下面给出的代码是什么意思?
- android - 拔下 USB 时,Android 9 中的前台服务暂停
- windows - 如何使用 git checkout 创建用于克隆存储库的 bash 脚本?
- python - 使用 Zip() 循环 For,选择要打印的记录数
- javascript - nodeJS Winston 模块示例未登录到控制台
- python - Plotting a Pandas series in Matplotlib/seaborn
- r - R中的文本分析:除了标记之外,如何向我的机器学习分类器添加变量?
- python - 如何以 YYYY-Qx 格式查找上一年的匹配值?
- python - Pandas - 创建具有相同优先级的类别的分类对象