我有一个Flutter应用(v1.2.1),我正在尝试调试一个错误,该错误无法在调试模式下重现。我知道根本原因是在空对象上调用forEach,但我正在尝试查找代码中所指的forEach。我不理解错误消息的“尝试调用”部分,并且在Dart NoSuchMethodError类文档中找不到任何有关它的详细信息。这是错误:
NoSuchMethodError: The method 'forEach' was called on null.
Receiver: null
Tried calling: forEach(Closure: (CustomObject) => Null)
该错误是否表示它发生在格式为forEach((CustomObject)=> {method body})的forEach或位于格式(CustomObject)=> {method body}的闭包内部的forEach中?
例如会是这样吗?
methodOne(List<CustomObject> fakeObjects) {
fakeObjects.forEach((CustomObject thingOne) {
print(thingOne);
});
}
或类似的内容:
methodTwo(CustomObject thingOne) {
...some code
listOfItems.forEach((String item) {
print(item);
});
}