AVOID using providers for Ephemeral state ( * generally everything that Flutter deals with a “controller” (e.g. TextEditingController))
If you are looking for a way to handle local widget state, consider using flutter_hooks instead.
The only reason to put a TextEditingController into a business object outside of the widget is if you want to access it out side the widget.
I can imagine such situations but they should be rare.
watch_it now has a createOnce function for exactly that situation so you don’t need a StatefulWidget.
@muhammadkamel I guess that question does not really have something to do with MVVM but where to store controllers. Maybe you find a better title?
One thing we have to make sure is that TextEditingController or other controllers have to be disposed when they are no longer needed.
Remember to dispose of the TextEditingController when it is no longer needed. This will ensure we discard any resources used by the object.
So I usually store them in State of StatefulWidget so that I can dispose them when dispose() is called, meaning synchronizing the widget’s and controller’s lifecycle perfectly.
I saw this in multiple projects … the main benefit from it, to uses it to store the value of the current state of that control or access the value from any place in your widget tree… using buildWhen method or listenWhen to avoid re-building the widget … i think it’s the replacement of the dispose method
Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.
Using contents of this forum for the purposes of training proprietary AI models is forbidden. Only if your AI model is free & open source, go ahead and scrape.