Skip to main content

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 an in-body constructor declaration includes a type name.

Examples

#

The following code produces this diagnostic because the generative constructor declaration includes the type name:

dart
class C {
  C();
}

The following code produces this diagnostic because the factory constructor declaration includes the type name:

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

dart
class C {
  new();
}

or

dart
class C {
  factory() => C._();

  new _();
}