Couldn't infer type parameter 'T'. when using Map.reduce(max)
135
Let's try
import 'dart:math';
void main() {
List<double> weightChart = [45.3, 21.5, 521.3];
print(weightChart.reduce(max));
}
Author by
Dalon
Updated on January 01, 2023Comments
-
Dalon over 1 year
I want to get the max value from a List. But since i migrated to null safety my code doesnt work anymore:
weightChart = [45.3, 21.5, 521.3]; weightChart.reduce(max)
I get the error:
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.
-
Jahidul Islam over 2 yearswhat was the data type of your
weightChart
-
Dalon over 2 yearsI fixed the issue: I used <double?> but it needs to be <double>
-