Skip to main content

dispose-getx-fields

added in: 1.18.0
Pro+

Warns when a widget state field is not disposed in the onClose method.

Not disposing fields that have a dispose method may lead to memory leaks and should be avoided.

Example

❌ Bad:

class _ShinyWidgetController extends GetxController {
final _someDisposable = SomeDisposable();
final _anotherDisposable = AnotherDisposable(); // LINT: This field is not disposed, which can lead to a memory leak. Try disposing this field in the widget's 'dispose' method.


void onClose() {
_someDisposable.dispose();

super.onClose();
}
}

✅ Good:

class _ShinyWidgetController extends GetxController {
final _someDisposable = SomeDisposable();
final _anotherDisposable = AnotherDisposable();


void onClose() {
_someDisposable.dispose();
_anotherDisposable.dispose(); // Correct, disposed

super.onClose();
}
}