always-remove-getx-listener
Warns when a GetX event listener is added but never removed.
Not removing event listeners may result in unexpected side effects and memory leaks.
Example
❌ Bad:
class VideoViewerController extends GetxController {
final _someListener = Listener();
final _anotherListener = Listener();
void onInit() {
_someListener.addListener(listener);
_anotherListener.addListener(listener); // LINT: This listener is not removed, which can lead to a memory leak.
}
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); // Correct, the listener is now removed
}
void listener() {
...
};
}