avoid_ redundant_ argument_ values
Details about the 'avoid_redundant_argument_values' diagnostic produced by the Dart analyzer.
The value of the argument is redundant because it matches the default value.
Description
#The analyzer produces this diagnostic when an argument is passed to an optional parameter of a function, but the argument's value is the same as the parameter's default value. The duplicative argument can often be removed without changing the behavior of the code.
When invoking methods, because the redundancy check is based on the static type of the invocation target, there can be false positives when a method override changes a parameter's default value. If the static type has one default value specified but the actual runtime type has another, the diagnostic might not be accurate.
Examples
#
The following code produces this diagnostic because the
named argument b has the same value as its default value of true:
void g({bool b = true}) {}
void f() {
g(b: true);
}
The following code produces this diagnostic because the
positional argument 1 has the same value as
the default value of the second parameter of g:
void g([int? a, int? b = 1]) {}
void f() {
g(0, 1);
}
Common fixes
#Remove the redundant argument from the invocation:
void g({bool b = true}) {}
void f() {
g();
}
void g([int? a, int? b = 1]) {}
void f() {
g(0);
}
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.