【发布时间】:2021-10-08 10:27:53
【问题描述】:
我想从列表中获取最大值。但是自从我迁移到 null 安全后,我的代码不再工作了:
weightChart = [45.3, 21.5, 521.3];
weightChart.reduce(max)
我得到错误:
Couldn't infer type parameter 'T'. Tried to infer 'double?' for 'T' which doesn't work: Type
parameter 'T' is declared to extend 'num' producing 'num'. The type 'double?' was inferred from:
Function type declared as 'T Function<T extends num>(T, T)' used where 'double? Function(double?,
double?)' is required. Consider passing explicit type argument(s) to the generic.
【问题讨论】:
-
你的
weightChart的数据类型是什么 -
我解决了这个问题:我使用了
但它必须是
标签: flutter dart mapreduce dart-null-safety