avoid-unnecessary-getter
Warns when a getter provides access to an existing final field without any additional logic.
⚙️ Config
Set ignore-upcast
(default is true
) to ignore getters with the different return type than the referenced field.
dart_code_metrics:
...
rules:
...
- avoid-unnecessary-getter:
ignore-upcast: false
Example
❌ Bad:
abstract class PageRoute<T> extends ModalRoute<T> {
PageRoute();
bool get barrierDismissible => _barrierDismissible; // LINT
final _barrierDismissible = false;
}
✅ Good:
abstract class PageRoute<T> extends ModalRoute<T> {
PageRoute();
final barrierDismissible = false;
String? _contents;
String? get contents => _contents;
set contents(String? value) {
_contents = value;
}
}