undefined_ static_ member_ write
Details about the 'undefined_static_member_write' diagnostic produced by the Dart analyzer.
The constant '{0}' in the {1} '{2}' can't be assigned to.
The function type '{0}' doesn't have a static setter named '{1}'.
The member '{0}' is declared in '{1}', but private names are visible only in their own library.
The static field '{0}' in the {1} '{2}' is final, so it can't be assigned to.
The {0} '{1}' doesn't have a static setter named '{2}'.
The {0} '{1}' in the {2} '{3}' can't be assigned to.
There's a static getter '{0}' in the {1} '{2}', but no setter.
Description
#The analyzer produces this diagnostic when a value is assigned to a static member of a class, enum, mixin, extension type, or extension, but the declaration doesn't have an accessible static setter or non-final static field with that name.
Examples
#
The following code produces this diagnostic because the class C
doesn't declare a static setter named b:
class C {
static int a = 0;
}
void f() {
C.b = 1;
}
The following code produces this diagnostic because the static field
a is final:
class C {
static final int a = 0;
}
void f() {
C.a = 1;
}
Common fixes
#If you intended to assign a different static member, then use its name:
class C {
static int a = 0;
}
void f() {
C.a = 1;
}
If the setter isn't declared, then declare it or remove the assignment.
Unless stated otherwise, the documentation on this site reflects Dart 3.13.3. Report an issue.