Flutter setting a value of TextFormField according to setState of a widget variable
how can i set the value of a TextFormField
from a widget variable when this variable changed according to a setstate
action after building the widget and not by the initial value of this textformfeild
what i know that i can change its value by using the TextEditingController
but i have too many TextFormField
and creating the TextEditingController
take a lot of code by using the traditional way by adding them the whole widget:
1-Create a TextEditingController.
2-Connect the TextEditingController to a text field.
3-Create a function to update the latest value.
4-Listen to the controller for changes.
is there any way to build this controller and do those steps inside the code of the TextFormField
only? or another way ?
Solution 1:
place controler in
TextFormField(
controller: TextEditingController(text: daytask),....
then place setstate() txt='';
like this
setState(() { txt='' }