With a Flutter form that uses TextFormField, how do I clear the text field after the form have been saved/submitted?
Do I have to use a Text controller?
With a Flutter form that uses TextFormField, how do I clear the text field after the form have been saved/submitted?
Do I have to use a Text controller?
3
Answers
First define
controller
:then use it like this:
here in
onFieldSubmitted
you can get thevalue
and save it in somewhere else and then clear thecontroller
and by thatTextFormField
will get clear.If you are using a Form widget, add a Key to it, and after submitting the form you can do:
_formKey.currentState?.reset();
This will reset the status of the TextFormFields that are contained in your Form.
Create a
TextEditingcontroller
dispose of it after use