Couldn't infer type parameter 'T'. when using Map.reduce(max) - flutter

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.

Let's try
import 'dart:math';
void main() {
List<double> weightChart = [45.3, 21.5, 521.3];
print(weightChart.reduce(max));
}

Related

Error inferring build function type during bloc testing

Couldn't infer type parameter 'B'.
Tried to infer 'CounterCubit?' for 'B' which doesn't work:
Type parameter 'B' is declared to extend 'BlocBase' producing 'BlocBase<_>'.
The type 'CounterCubit?' was inferred from:
Parameter 'build' declared as 'B Function()'
but argument is 'CounterCubit? Function()'.
Consider passing explicit type argument(s) to the generic.

function as parameter with generic object return type in dart

I have a function defined as
final Function<Future<PageableModel<T>>>(String?) elementBuilder;
The compiler shows a compile error at "Future": Expected to find '>'.
Is it possible in Dart to define a generic object as the return type of a function defined as variable.
That is not valid syntax. You probably meant:
final Future<PageableModel<T>> Function(String?) elementBuilder;

Why can't assign the generic variables in Dart?

Why can't assign the generic variables in Dart?
void test<T1 extends num, T2 extends String>(T2 arg) {
// ↓ A value of type 'int' can't be assigned to a variable of type 'T1'. Try changing the type of the variable, or casting the right-hand type to 'T1'.
T1 t = 0;
// ↓↓↓↓ A value of type 'String' can't be assigned to a variable of type 'T2'. Try changing the type of the variable, or casting the right-hand type to 'T2'.
arg = 'Test';
}

Flutter Problem about Constructor return type

The constructor returns type 'dynamic' that isn't of expected type 'Widget'.dart(invalid_cast_new_expr)

Argument type '{directives: any[];}' is not assignable to parameter of type 'NgModule'

I am getting this error:
Argument type '{directives: any[];}' is not assignable to parameter of type 'NgModule'
Here is a screenshot: