If i initialise a watcher in the initState() e.g.
textController.addListener(textTypedListener);
Do i need to manually remove the listener before I dispose of the text controller? or does the dispose automatically handle this.
eg. Options 1
@override
void dispose() {
textController.removeListener(textTypedListener);
textController.dispose();
super.dispose();
}
Option 2
@override
void dispose() {
textController.dispose();
super.dispose();
}
Which is best?
Thanks a lot.
According to the Interactive Example given in the flutter documentation of Handle changes to a text field, it's commented that calling dispose also removes the listener.
So the second option would be best.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With