Skip to main content

no_annotation_constructor_arguments

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

Annotation creation must have arguments.

Description

#

The analyzer produces this diagnostic when an annotation is the name of a class, such as @C, or of a constructor, such as @C.named, rather than the name of a variable. To create an instance of the class, the name must be followed by an argument list. This diagnostic is reported whether or not the constructor is a const constructor.

Example

#

The following code produces this diagnostic because C is a class, and a class can't be used as an annotation without invoking a const constructor from the class:

dart
class C {
  const C();
}
​
@C
var x = 0;

Common fixes

#

Add the missing argument list:

dart
class C {
  const C();
}
​
@C()
var x = 0;