I want to know what is the right way to dispose all text editing controllers in a list in flutter?
List<TextEditingController> controllers = [];
I tried this, but it’s not working. What should be the correct approach for it?
dispose(){
for(TextEditingController controller in controllers){
controller.dispose();
}
}
2
Answers
You are trying to call
dispose
on yourList<TextEditingController>
and not on yourTextEditingController
. You need to change it inside your for loop body.You are calling on wrong variable: