static_access_to_instance_member
Instance member '{0}' can't be accessed using static access.
Description
#The analyzer produces this diagnostic when a class name is used to access an instance field. Instance fields don't exist on a class; they exist only on an instance of the class.
Example
#The following code produces this diagnostic because x
is an instance field:
class C {
static int a = 0;
int b = 0;
}
int f() => C.b;
Common fixes
#If you intend to access a static field, then change the name of the field to an existing static field:
class C {
static int a = 0;
int b = 0;
}
int f() => C.a;
If you intend to access the instance field, then use an instance of the class to access the field:
class C {
static int a = 0;
int b = 0;
}
int f(C c) => c.b;
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.