Skip to main content

always-remove-getx-listener

added in: 1.18.0
Pro+

Warns when a GetX event listener is added but never removed.

Example

❌ Bad:

class VideoViewerController extends GetxController {
final _someListener = Listener();
final _anotherListener = Listener();


void onInit() {
_someListener.addListener(listener);
_anotherListener.addListener(listener); // LINT
}


void onClose() {
_someListener.removeListener(listener);
}

void listener() {
...
};
}

✅ Good:

class VideoViewerController extends GetxController {
final _someListener = Listener();
final _anotherListener = Listener();


void onInit() {
_someListener.addListener(listener);
_anotherListener.addListener(listener);
}


void onClose() {
_someListener.removeListener(listener);
_anotherListener.removeListener(listener);
}

void listener() {
...
};
}