avoid_ unused_ constructor_ parameters
Details about the 'avoid_unused_constructor_parameters' diagnostic produced by the Dart analyzer.
The parameter '{0}' is not used in the constructor.
Description
#
The analyzer produces this diagnostic when a constructor parameter
isn't used in the constructor body or initializer list, and isn't an
initializing formal parameter (this.x), a super parameter (super.x),
or a declaring parameter.
Parameters that are only declared but never referenced are likely unintentional and add unnecessary complexity to the constructor.
Examples
#
The following code produces this diagnostic because
the parameter x isn't used in the constructor:
class C {
C(int x);
}
The following code produces this diagnostic because
the parameter c isn't used in the constructor initializer list:
class C {
int x;
C(int a, int b, int c): x = a + b {
print(x);
}
}
Common fixes
#If the parameter is meant to initialize a field, then use an initializing formal parameter:
class C {
int x;
C(this.x);
}
If the parameter isn't needed, then remove it:
class C {
int x;
C(int a, int b): x = a + b {
print(x);
}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.