我使用 .fold() 方法对列表求和时出错:
List<int> listInt = [1, 2, 3, 4, 5, 6];
int sumList = listInt.fold(0, (p, c) => p + c);
// First Print
print(sumList);
// Second Pring
print(listInt.fold(0, (p, c) => p + c));
Run Code Online (Sandbox Code Playgroud)
打印 sumList 完全没问题,但是当我打印相同的操作时,我收到编译错误:
The operator '+' can't be unconditionally invoked because the receiver can be 'null'.
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
dart ×1