I'm working on a refactored code to separated small piece of widgets.
There's several columns with TextFields
in each one of them.I have two options to complete the task :
Choosing StatelessWidget
since it have more performance, may put TextEditingController related code outside of sub widgets. Or include some logic in onChanged
event. but still there's some events like clear text
can't put in onChanged
event
Choosing StatefulWidget
if I use TextEditingController
include inside each sub widget.
How to choose between StatelessWidget
and StatefulWidget
when refactoring code into small widgets like this ?
Update
Here's my current conclusion which can be updated if it's not correct.
FocusNode
of TextEdit
in parent since it's related to brother focusNode & parentNode;TextEdtingController
in parent, which will be useful in cases like when TextField
is out of screen like a ListItem
scrolled out of the screen, which will make the whole widget unmounted. The state will be preserved.animation self
like shaking TextField
when inputting something wrong in self. Since it's a feature of the TextField
not related to the parent.Edit in response to the discussion in the comments section:
You should go with the second approach when refactoring your code into smaller StatefulWidgets
. And the parent
should have a function to alter the nested TextFields' content and its animation
behavior by calling functions inside it, as you earlier indicated you need to manage this behavior.