getter_hides_super_field
Reports a getter that overrides a superclass field its own class’s constructor passes a value to. Read the stored value through super, or stop asking for it.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- strict
- Fix
- none
What it reports
Section titled “What it reports”A getter that overrides a field of a superclass, where a constructor of the getter’s class passes that field a value. The value is stored and nothing reads it: every read of the name, the superclass’s own included, runs the getter. The violation is on the getter’s name.
A value counts as passed where a constructor of the class has a super parameter, or gives the super constructor an argument, that ends at a field formal parameter of that field, through any chain of super parameters. A constant written in the class (a literal, a const value or the name of a constant) does not count: it fills a parameter the superclass requires.
It does not report:
- a class that reads the field through
superanywhere; - an abstract getter;
- an override of a member that is written as a getter;
- a field over a field, which the SDK lint
overridden_fieldsreports.
Every caller passes a value that changes nothing, and the constructor’s signature still asks for it. The rule cannot tell which of the two you meant, the stored value or the computed one, so it offers no fix.
Example
Section titled “Example”class Child extends Base { Child(super.value);
@override int get value => 0;}class Child extends Base { Child(super.value);
@override int get value => super.value.clamp(0, 10);}Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression, which goes above the line of the getter’s name:
// The base requires a value; this subclass computes its own.// ignore: getter_hides_super_fieldint get value => 0;// ignore_for_file: assay/getter_hides_super_field silences it in a whole file, and // ignore: assay/getter_hides_super_field with the prefix works too. See Suppressions.