Skip to main content

undefined_extension_member_write

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

The extension '{0}' doesn't have an instance setter named '{1}'.

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

The {0} '{1}' in the extension '{2}' can't be assigned to.

There's a getter '{0}' in the extension '{1}', but no setter.

Description

#

The analyzer produces this diagnostic when an extension override is used to assign to a member, but the extension doesn't declare an instance setter with that name.

Examples

#

The following code produces this diagnostic because the extension E doesn't declare a setter named b:

dart
extension E on String {
  set a(String _) {}
}
​
void f() {
  E('c').b = 'd';
}

The following code produces this diagnostic because the extension E declares only a getter named a:

dart
extension E on String {
  String get a => 'a';
}
​
void f() {
  E('c').a = 'd';
}

Common fixes

#

If you intended to use a different setter of the extension, then use its name:

dart
extension E on String {
  set a(String _) {}
}
​
void f() {
  E('c').a = 'd';
}

If the setter isn't declared, then declare it in the extension, or remove the assignment.