小编Bre*_*Kid的帖子

Dart Fold 方法错误 - 对列表 int 求和

我使用 .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

5
推荐指数
1
解决办法
268
查看次数

标签 统计

dart ×1