avoid-ref-inside-state-dispose
Warns when ref
is used inside the dispose
method.
At disposal, providers may already be disposed, and accessing them can lead to unexpected errors or inconsistent behavior.
Example
❌ Bad:
class _SomeState extends ConsumerState<SomeWidget> {
void dispose() {
// LINT: Avoid using 'Ref' inside the 'dispose' method.
ref.read(provider).doSomething();
super.dispose();
}
}
✅ Good:
class _SomeState extends ConsumerState<SomeWidget> {
void dispose() {
super.dispose();
}
}