Skip to main content

undefined_unqualified_name_read

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

There's a setter '{0}', but no getter.

Undefined name '{0}' used as an annotation.

Undefined name '{0}'.

Description

#

The analyzer produces this diagnostic when a name without a qualifier is read, invoked, or torn off, but there's no variable, getter, function, method, or type with that name in the scope in which it's used.

Examples

#

The following code produces this diagnostic because the name rihgt isn't defined:

dart
int min(int left, int right) => left <= rihgt ? left : right;

The following code produces this diagnostic because there's no function named emty:

dart
List<int> empty() => [];
​
void main() {
  print(emty());
}

The following code produces this diagnostic because C doesn't have a member named removeMiddle:

dart
class C {
  void removeLast() {}
​
  void f() {
    removeMiddle();
  }
}

The following code produces this diagnostic because there's only a setter named x, which can't be read:

dart
set x(int _) {}
​
int f() => x;

The following code produces this diagnostic because there's no constant named deprecatedApi to use as an annotation:

dart
@deprecatedApi
void f() {}

Common fixes

#

If the name is misspelled, then correct it:

dart
int min(int left, int right) => left <= right ? left : right;

If the name is declared in a library that isn't imported, then import that library.

If the name isn't declared, then declare it. An annotation without arguments, and a constant expression, can use only a constant:

dart
const deprecatedApi = 'Use g instead.';
​
@deprecatedApi
void f() {}

If there's only a setter, then add a getter with the same name:

dart
int get x => 0;
​
set x(int _) {}
​
int f() => x;