Flutter 颤振移除(…)悬挂列表的位置
我正在努力处理以下由函数调用的代码,但它“挂起”。当代码在for循环中迭代时,第一次找到匹配项并尝试删除时,它将挂起,不再继续:Flutter 颤振移除(…)悬挂列表的位置,flutter,Flutter,我正在努力处理以下由函数调用的代码,但它“挂起”。当代码在for循环中迭代时,第一次找到匹配项并尝试删除时,它将挂起,不再继续: for (var anItem in myItems) { String s = aFunction(anItem.someField); var matches= myItems.where((e) => aFunction(e.someField) == s); if (matches.length > 1) { myItems
for (var anItem in myItems) {
String s = aFunction(anItem.someField);
var matches= myItems.where((e) => aFunction(e.someField) == s);
if (matches.length > 1) {
myItems.removeWhere((e) => aFunction(e.someField) == s); // Hangs Here
}
}
在
myItems.where
和myItems.removeWhere
中,您有一个传递的e
元素,它在您的表达式中根本没有使用-我建议先阅读,这是一个我已经纠正的错误-我正在删除代码中的一些额外内容。是的,它是基于对象的字段删除重复项。在应用程序中刷新,而不是重新加载会产生:未处理的异常:迭代期间的并发修改:“\u GrowtableList”的实例(长度:9)。