unnecessary_ type_ name_ in_ constructor
Details about the 'unnecessary_type_name_in_constructor' diagnostic produced by the Dart analyzer.
Unnecessary type name in a constructor.
Description
#The analyzer produces this diagnostic when a secondary constructor declaration includes a type name.
Examples
#The following code produces this diagnostic because the generative constructor declaration includes the type name:
class C {
C();
}
The following code produces this diagnostic because the factory constructor declaration includes the type name:
class C {
factory C() => C._();
new _() {}
}
Common fixes
#Remove the type name from the constructor. If the constructor is named, also remove the period before the name:
class C {
new ();
}
or
class C {
factory () => C._();
new _() {}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.