instance_ access_ to_ static_ member
The static {0} '{1}' can't be accessed through an instance.
Description
#The analyzer produces this diagnostic when an access operator is used to access a static member through an instance of the class.
Example
#
The following code produces this diagnostic because
zero
is a static
field, but it's being accessed as if it were an instance field:
void f(C c) {
c.zero;
}
class C {
static int zero = 0;
}
Common fixes
#Use the class to access the static member:
void f(C c) {
C.zero;
}
class C {
static int zero = 0;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.