首页 > 解决方案 > 类没有实例方法`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)));

标签: flutterdart

解决方案


这里的问题是你使用括号()来访问你的元素List,它试图call在你的对象上调用,但由于你的对象不是函数,这会引发错误。

但是,List使用方括号[]访问给定索引处的对象

这意味着它很容易解决,只需用方括号替换括号:

return RepTile(RepData.fromDocument(snapshot.data.documents[index]));

推荐阅读