Skip to main content

avoid-unnecessary-overrides-in-state

added in: 1.7.0
🛠
Pro+
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> {
// LINT: This overridden method does not have any additional logic. Try removing it.

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

// LINT: This overridden method does not have any additional logic. Try removing it.

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

✅ Good:

class _FooState extends State<SomeWidget> {

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


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