Why this matters
Prevents background work and resource leaks after widget teardown.
Dispose controllers, focus nodes, animations, timers, and cancel subscriptions in dispose().
Prevents background work and resource leaks after widget teardown.
Side-by-side examples engineers can pattern-match during review.
class MyState extends State<MyWidget> {
final controller = TextEditingController();
}class MyState extends State<MyWidget> {
final controller = TextEditingController();
StreamSubscription<int>? sub;
@override
void dispose() {
controller.dispose();
sub?.cancel();
super.dispose();
}
}Timer.periodic(...); // never canceledlate final t = Timer(...); @override dispose() => t.cancel();From the same buckets as this rule.