Skip to main content

use_declaring_parameters

Details about the 'use_declaring_parameters' diagnostic produced by the Dart analyzer.

Use a declaring parameter.

Description

#

The analyzer produces this diagnostic when a primary constructor has a parameter whose name matches a field of the same type in the class, and the constructor assigns the value to the field without modifying it.

Example

#

The following code produces this diagnostic because the constructor assigns the parameter i to the field i:

dart
class C(int i) {
  final int i;

  this : i = i;
}

Common fixes

#

Convert the parameter to a declaring parameter:

dart
class C(final int i);