Skip to main content

avoid-accessing-other-classes-private-members

added in: 1.7.0

Warns when a private member of another class is used.

While Dart allows accessing private members of other classes in the same library, accessing them still violates encapsulation. Consider marking these members public or reorganizing the code.

Example

❌ Bad:

class SomeClass {
final String _value;

const SomeClass(this._value);
}

class OtherClass {
void work(SomeClass other) {
other._value; // LINT
}
}

✅ Good:

class SomeClass {
final String value;

const SomeClass(this.value);
}

class OtherClass {
void work(SomeClass other) {
other.value;
}
}