Incompatible function signature for `Future.catchError` argumentDRT-W1226
The analyzer produces this diagnostic when an invocation of
Future.catchError has an argument that is a function whose parameters
aren't compatible with the arguments that will be passed to the function
when it's invoked. The static type of the first argument to catchError
is just Function, even though the function that is passed in is expected
to have either a single parameter of type Object or two parameters of
type Object and StackTrace.
Examples
The following code produces this diagnostic because the closure being
passed to catchError doesn't take any parameters, but the function is
required to take at least one parameter:
void f(Future<int> f) {
f.catchError(() => 0);
}
The following code produces this diagnostic because the closure being
passed to catchError takes three parameters, but it can't have more than
two required parameters:
void f(Future<int> f) {
f.catchError((one, two, three) => 0);
}
The following code produces this diagnostic because even though the closure
being passed to catchError takes one parameter, the closure doesn't have
a type that is compatible with Object:
void f(Future<int> f) {
f.catchError((String error) => 0);
}
Common fixes
Change the function being passed to catchError so that it has either one
or two required parameters, and the parameters have the required types:
void f(Future<int> f) {
f.catchError((Object error) => 0);
}