Flutter TextFormField onChanged event

Viewed 9763

I want to build autocomplete using TextFormField, I don't know how to create OnChanged event for TextFormField My requirement is there will be text field with some text, if user edits that text, textfield should behave like auto suggest.

2 Answers

Lucky for us the onChanged option in the TextFormField is already available. If you update flutter and doesn't work just go to the text_form_field.dart file by clicking on the Widget TextFormField + command/control and modify the text with code in the link: text_form_field.dart

Are you wrapping TextFormField in a FormField widget? If not, I suggest to use just TextField which has an onChange property

Edit: To set an initial value you can add a TextEditingController and asign it to the TextFormField

TextEditingController _controller = TextEditingController();

then in initState() you can do

_controller.text = 'Initial Value'
Related