Skip to main content

avoid-unnecessary-overrides-in-state

added in: 1.7.0
🛠
preset: recommended

Warns when a widget's State has unnecessary overrides.

Standard rule for unnecessary overrides does not trigger if a declaration has different annotations (and for State some of them are marked as @protected). This rule does not have this limitation.

Example

❌ Bad:

class _FooState extends State<SomeWidget> {

void dispose() {
super.dispose(); // LINT
}


void initState() => super.initState(); // LINT
}

✅ Good:

class _FooState extends State<SomeWidget> {

void dispose() {
// Comment or additional implementation
super.dispose();
}


void initState() {
// Comment or additional implementation
super.initState();
}
}