Flutter TextFormField onChanged event

9,573

Solution 1

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'

Solution 2

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

Share:
9,573
SHASHI KUMAR S
Author by

SHASHI KUMAR S

Enthusiastic programmer Love Windows

Updated on December 07, 2022

Comments

  • SHASHI KUMAR S
    SHASHI KUMAR S 11 months

    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.

  • SHASHI KUMAR S
    SHASHI KUMAR S about 5 years
    yes I am wrapping TextFormField in a FormField widget. Is it possible to set TextField value through code like initialValue of TextFormField?
  • Sebastian
    Sebastian about 5 years
    @SHASHIKUMARS I've just updated my answer. Let me know if it helps
  • Sebastian
    Sebastian about 5 years
    @SHASHIKUMARS you can check this question out stackoverflow.com/questions/48870082/… it may help you