proper-super-calls
preset: recommended
Checks that super
calls in the initState
and dispose
methods are called in the correct order.
Calling these super
methods in the wrong order can lead to bugs when some properties are not yet initialized or have already been disposed.
Example
❌ Bad:
class _MyHomePageState<T> extends State<MyHomePage> {
int _counter = 0;
void initState() {
someWork();
// LINT: This 'super' call must come first.
super.initState();
}
void dispose() {
// LINT: This 'super' call must come last.
super.dispose();
someWork();
}
}
✅ Good:
class _MyHomePageState<T> extends State<MyHomePage> {
int _counter = 0;
void initState() {
super.initState();
someWork();
}
void dispose() {
someWork();
super.dispose();
}
}