undefined_ super_ member_ write
Details about the 'undefined_super_member_write' diagnostic produced by the Dart analyzer.
The field '{0}' in a superclass of '{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 in a superclass of '{1}'.
The {0} '{1}' in a superclass of '{2}' can't be assigned to.
There's a getter '{0}' in a superclass of '{1}', but no setter.
Description
#
The analyzer produces this diagnostic when a member is assigned using
super, but no superclass of the enclosing declaration has a setter or a
non-final field with that name.
Examples
#
The following code produces this diagnostic because the superclass A
doesn't define a setter named bar:
class A {
set foo(int _) {}
}
class B extends A {
void m() {
super.bar = 0;
}
}
The following code produces this diagnostic because the superclass A
defines only a getter named foo:
class A {
int get foo => 0;
}
class B extends A {
void m() {
super.foo = 0;
}
}
The following code produces this diagnostic because the field foo in
the superclass A is final:
class A {
final int foo = 0;
}
class B extends A {
void m() {
super.foo = 0;
}
}
Common fixes
#If the inherited setter you intend to use has a different name, then make the name match the inherited setter:
class A {
set foo(int _) {}
}
class B extends A {
void m() {
super.foo = 0;
}
}
If the setter isn't defined, then add it to a superclass:
class A {
set foo(int _) {}
set bar(int _) {}
}
class B extends A {
void m() {
super.bar = 0;
}
}
If a superclass defines only a getter, then add a setter with the same name:
class A {
int get foo => 0;
set foo(int _) {}
}
class B extends A {
void m() {
super.foo = 0;
}
}
If the field in the superclass is final, then make it non-final:
class A {
int foo = 0;
}
class B extends A {
void m() {
super.foo = 0;
}
}
Otherwise, remove the assignment.
Unless stated otherwise, the documentation on this site reflects Dart 3.13.3. Report an issue.