avoid_ types_ on_ closure_ parameters
Details about the 'avoid_types_on_closure_parameters' diagnostic produced by the Dart analyzer.
Unnecessary type annotation on a function expression parameter.
Description
#The analyzer produces this diagnostic when a parameter of a function expression (closure) has an explicit type annotation, and the closure is in a context where the parameter type can be inferred.
Example
#
The following code produces this diagnostic because
the parameter x in the closure passed to l.map has an
explicit type annotation of int, which is unnecessary because
the type can be inferred from the list's type:
void f(List<int> l) {
l.map((int x) => x.isEven);
}
Common fixes
#Remove the type annotation:
void f(List<int> l) {
l.map((x) => x.isEven);
}
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.