Skip to main content

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:

dart
var count = 0;
​
void f() {
  cuont = 1;
}

The following code produces this diagnostic because there's only a getter named x:

dart
int get x => 0;
​
void f() {
  x = 1;
}

The following code produces this diagnostic because y is final:

dart
final y = 0;
​
void f() {
  y = 1;
}

The following code produces this diagnostic because m is a method:

dart
class C {
  void m() {}
​
  void f() {
    m = () {};
  }
}

Common fixes

#

If the name is misspelled, then correct it:

dart
var count = 0;
​
void f() {
  count = 1;
}

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

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

If the variable is final, then make it non-final:

dart
var y = 0;
​
void f() {
  y = 1;
}

Otherwise, remove the assignment, or assign to a variable instead.