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 inonChanged
event. but still there's some events likeclear text
can't put inonChanged
eventChoosing
StatefulWidget
if I useTextEditingController
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.
- Prefer to put
FocusNode
ofTextEdit
in parent since it's related to brother focusNode & parentNode; - Prefer to put
TextEdtingController
in parent, which will be useful in cases like whenTextField
is out of screen like aListItem
scrolled out of the screen, which will make the whole widget unmounted. The state will be preserved. - Preferring to put
animation self
like shakingTextField
when inputting something wrong in self. Since it's a feature of theTextField
not related to the parent.