类没有实例方法`call` [英] Class has no instance method `call`

查看:217
本文介绍了类没有实例方法`call`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的代码中收到以下 NoSuchMethodError

I receive the following NoSuchMethodError in my code:

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 中的元素,该元素试图调用调用在您的对象上,但是由于您的对象不是函数,因此会引发错误。

The issue here is that your are using parentheses () to access an element in your List, which tries to invoke call on your object, but since your object is not a function, this throws an error.

但是,列表使用方括号 [] 访问指定索引处的对象

这是一个简单的解决方法,只需用方括号替换括号即可:

This means that it is an easy fix, just replace your parentheses by square brackets:

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

这篇关于类没有实例方法`call`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆