undefined_ unqualified_ name_ write
Details about the 'undefined_unqualified_name_write' diagnostic produced by the Dart analyzer.
'{0}' is final, so it can't be assigned to.
The constant '{0}' can't be assigned to.
The {0} '{1}' can't be assigned to.
There's a getter '{0}', but no setter.
Undefined name '{0}'.
Description
#The analyzer produces this diagnostic when a name without a qualifier is assigned, but there's no setter or variable that can be assigned with that name in the scope in which it's used.
Examples
#
The following code produces this diagnostic because the name cuont
isn't defined:
var count = 0;
void f() {
cuont = 1;
}
The following code produces this diagnostic because there's only a
getter named x:
int get x => 0;
void f() {
x = 1;
}
The following code produces this diagnostic because y is final:
final y = 0;
void f() {
y = 1;
}
The following code produces this diagnostic because m is a method:
class C {
void m() {}
void f() {
m = () {};
}
}
Common fixes
#If the name is misspelled, then correct it:
var count = 0;
void f() {
count = 1;
}
If there's only a getter, then add a setter with the same name:
int get x => 0;
set x(int _) {}
void f() {
x = 1;
}
If the variable is final, then make it non-final:
var y = 0;
void f() {
y = 1;
}
Otherwise, remove the assignment, or assign to a variable instead.
Unless stated otherwise, the documentation on this site reflects Dart 3.13.3. Report an issue.