undefined_ static_ member_ read
Details about the 'undefined_static_member_read' diagnostic produced by the Dart analyzer.
The context type '{0}' doesn't have a {1} named '{2}'.
The context type '{0}' doesn't have static members or constructors.
The context type '{0}' is declared in '{1}', but private names are visible only in their own library.
The function type '{0}' doesn't have a static member named '{1}'.
The member '{0}' is declared in '{1}', but private names are visible only in their own library.
The {0} '{1}' doesn't have a {2} named '{3}'.
There's a static setter '{0}' in the {1} '{2}', but no getter.
Description
#The analyzer produces this diagnostic when a static member of a class, enum, mixin, extension type, or extension is read, invoked, or torn off, but the declaration doesn't have an accessible static method, getter, or field with that name. For an enum, static members include its enum values.
For a dot shorthand such as .a, the analyzer looks up the name in the
declaration of its context type. It also produces this diagnostic when
the context type, such as a function type, doesn't have static members.
Examples
#
The following code produces this diagnostic because the class C
doesn't declare a static member named b:
class C {
static int a = 0;
}
var x = C.b;
The following code produces this diagnostic because the enum E
doesn't have a value named c:
enum E { a, b }
var e = E.c;
The following code produces this diagnostic because the enum E, which
is the context type of the dot shorthand .c, doesn't have a value
named c:
enum E { a, b }
E e = .c;
Common fixes
#If you intended to use a different static member, then use its name:
class C {
static int a = 0;
}
var x = C.a;
If the member isn't declared, then declare it or remove the reference.
Unless stated otherwise, the documentation on this site reflects Dart 3.13.3. Report an issue.