简体   繁体   中英

Flutter TextFormField onChanged event

我想使用TextFormField构建自动完成功能,我不知道如何为TextFormField创建OnChanged事件。我的要求是将文本字段包含一些文本,如果用户编辑该文本,则文本字段应表现为自动建议。

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'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM