Iterable toList()抛出-ArgumentError(无效参数)(输入):不能为null)

Iterable toList()抛出-ArgumentError(无效参数)(输入):不能为null),list,flutter,dart,iterable,List,Flutter,Dart,Iterable,我试图从我的iterable中列出一个列表,但它抛出了以下错误 发生异常。ArgumentError(无效参数)(输入): 不能为空) 关于 List iterable=(等待pluginContactService.ContactsService.getContacts(带缩略图:false)) .where((contact)=>contact.phones.firstWhere((item)=>item.label=='mobile',orElse:()=>null)?.value!=nu

我试图从我的iterable中列出一个列表,但它抛出了以下错误

发生异常。ArgumentError(无效参数)(输入): 不能为空)

关于

List iterable=(等待pluginContactService.ContactsService.getContacts(带缩略图:false))
.where((contact)=>contact.phones.firstWhere((item)=>item.label=='mobile',orElse:()=>null)?.value!=null)
.map((联系人)=>联系人模型(
contact.displayName,contact.phones.firstWhere((item)=>item.label=='mobile').value)).toList(可增长:false);

它一次又一次地重复这个异常。如果我关闭异常,我会得到一个包含预期结果的列表。如何处理此异常?

此错误:
ArgumentError(无效参数输入:不得为null)
表示
.toList(可增长:false)调用
null

因此,在调用
.toList()
或使用像
这样的默认值之前,应该检查它是否为null??[]
以修复此错误

??[]
可以修复

final tmp=(等待plugincontact服务
.联系服务
.getContacts(带缩略图:false)
)
.在哪里(
(contact)=>contact.phones.firstWhere(
(项目)=>item.label=='mobile',
orElse:()=>null
)?.值!=null
)
.map((联系人)=>联系人模型(
contact.displayName,
联系。电话。第一个在哪里(
(项目)=>item.label=='mobile'
)(价值)
);
列表iterable=tmp==null?[]:tmp.toList(可增长:false);


关闭调试会话设置中的“所有异常中断”可以解决此问题。

如果要显示代码,最好使用代码而不是图像。是否更新了问题@JerryZhouline number,character number?指出显示问题的输出的确切位置异常显示在.toList上(growtable:false);最后,它并不能解决问题。你能解释一下你想做什么吗?它仍然会生成异常。@MikeOttink请尝试新的。
List<ContactModel> iterable = (await pluginContactService.ContactsService.getContacts(withThumbnails: false))
    .where((contact) => contact.phones.firstWhere((item) => item.label == 'mobile', orElse: () => null)?.value != null)
    .map((contact) => ContactModel(
        contact.displayName, contact.phones.firstWhere((item) => item.label == 'mobile').value)).toList(growable: false);