Skip to main content

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:

dart
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:

dart
void g([int? a, int? b = 1]) {}

void f() {
  g(0, 1);
}

Common fixes

#

Remove the redundant argument from the invocation:

dart
void g({bool b = true}) {}

void f() {
  g();
}
dart
void g([int? a, int? b = 1]) {}

void f() {
  g(0);
}