我的代码有什么问题?widget.woList
这个数据类型是 List<HashMap<int, ABC>>()
for (var i in widget.woList) {
print(i.toString());
}
通过打印上面的代码,我得到
{5838: ABC(pid: 84201,userId: 545)}
但是,当我只想获取 key (
print(i.key.toString());
)时,出现以下错误:Class '_HashMap<int, ABC>' has no instance getter 'key'.
Receiver: Instance of '_HashMap<int, ABC>'
Tried calling: key
最佳答案
我认为您还需要遍历 HashMap :
for (HashMap<int, ABC> i in list) {
i.forEach((key, value) {
print(key.toString());
print(value.toString());
});
}
确保在 for 中使用
HashMap<int, ABC>
输入“i”变量。从您的 IDE 获取自动完成。
关于dart - HashMap 没有实例键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61556690/