unused_ field_ from_ primary_ constructor
Details about the 'unused_field_from_primary_constructor' diagnostic produced by the Dart analyzer.
The value of the field '{0}' isn't used.
Description
#The analyzer produces this diagnostic when a private field is declared in a primary constructor but never read, even if it's written in one or more places.
Example
#
The following code produces this diagnostic because the field
_i isn't read anywhere in the library:
class C(final int _i);
The primary constructor declares a field because the keyword final is
used. (Using the var keyword also declares a field.)
Common fixes
#
If the parameter is still necessary, but the associated field is not, then
remove the final or var keyword:
class C(int _i);
If the parameter is also unnecessary, then remove it (which also removes the associated field).
class C {}
If the field was intended to be used, then add the missing code.
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.