Skip to main content

undefined_instance_member_write

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

The field '{0}' of the type '{1}' is final, so it can't be assigned to.

The member '{0}' is declared in '{1}', but private names are visible only in their own library.

The setter '{0}' isn't defined for the type '{1}'.

The {0} '{1}' of the type '{2}' can't be assigned to.

There's a getter '{0}' for the type '{1}', but no setter.

Description

#

The analyzer produces this diagnostic when an instance member is assigned, but neither the static type of the receiver nor any applicable extension has an accessible setter or non-final field with that name.

Examples

#

The following code produces this diagnostic because C doesn't have a setter named z:

dart
class C {
  int x = 0;
}
​
void f(C c) {
  c.z = 0;
}

The following code produces this diagnostic because C has only a getter named x:

dart
class C {
  int get x => 0;
}
​
void f(C c) {
  c.x = 0;
}

The following code produces this diagnostic because the field x is final:

dart
class C {
  final int x = 0;
}
​
void f(C c) {
  c.x = 0;
}

Common fixes

#

If the setter you intend to use has a different name, then change the name to match:

dart
class C {
  int x = 0;
}
​
void f(C c) {
  c.x = 0;
}

If the setter is declared in an extension that isn't imported, then import the library that declares the extension.

If the type has only a getter, then add a setter with the same name:

dart
class C {
  int get x => 0;
​
  set x(int _) {}
}
​
void f(C c) {
  c.x = 0;
}

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

dart
class C {
  int x = 0;
}
​
void f(C c) {
  c.x = 0;
}

Otherwise, remove the assignment.