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:
int min(int left, int right) => left <= rihgt ? left : right;
The following code produces this diagnostic because there's no function
named emty:
List<int> empty() => [];
void main() {
print(emty());
}
The following code produces this diagnostic because C doesn't have a
member named removeMiddle:
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:
set x(int _) {}
int f() => x;
The following code produces this diagnostic because there's no
constant named deprecatedApi to use as an annotation:
@deprecatedApi
void f() {}
Common fixes
#If the name is misspelled, then correct it:
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:
const deprecatedApi = 'Use g instead.';
@deprecatedApi
void f() {}
If there's only a setter, then add a getter with the same name:
int get x => 0;
set x(int _) {}
int f() => x;
Unless stated otherwise, the documentation on this site reflects Dart 3.13.3. Report an issue.