Skip to main content

prefer-private-extension-type-field

added in: 1.15.0
🛠
Dart 3.3+
Pro+
preset: recommended

Warns when an extension type has a public representation field.

Public representation fields can be accessed directly, which may lead to potential mistakes. Consider exposing only the required properties or methods.

Example

❌ Bad:

// LINT: Avoid exposing the representation field. Try making it private.
extension type ET(String value) {}

✅ Good:

extension type ET(String _value) {
bool get isCorrect => _value.isNotEmpty;
}