1

How can I know when the done key is pressed on the TextFormField, and clear what is written and save what is written in a list?

2 Answers2

1

you can do it with onsubmitted: function in text field
this function will call when user submits the text ,
you can also control the action with textInputAction like below

textInputAction: TextInputAction.done,
Yaya
  • 4,402
  • 4
  • 19
  • 43
1

For the part to clear values of TextFormField you can do the following according to this:

String selectedValue;
List selectedValueList;
 var _controller = TextEditingController();
    List selectedValuesList;
    String selectedValue;
          TextFormField(
            controller: _controller,
            labelText: "Enter value"),
            onChanged: (value) {
                  setState(() {
                       selectedValue = value;
                            });
                          },
                        ),

and whenever you want to clear it you can call the folowing

    controller.clear(),

for the done key I don't know exactly what you're after but you can check something like this if it can help you to get to what you want, and by the time that that done key is pressed you do the following:

selectedValueList.add(selectedValue);
selectedValue="";
_controller.clear(),
Shalabyer
  • 555
  • 7
  • 23