DeepSource has joined Harness. Learn more
Dart Analyze logoDart Analyze/
DRT-W1622

Invalid use of static access to instance memberDRT-W1622

Major severityMajor
Bug Risk categoryBug Risk

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;

  int b;
}

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;

  int b;
}

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;

  int b;
}

int f(C c) => c.b;