简体   繁体   中英

Flutter TextFormField how to add manual onChange property

I added TextEditingController to my TextFormField for reading the user input, but I want to read the input at every update in the TextFormField, and the Controller shows previous updates. In short I want an alternative to something like onChanged method in TextField, since I'm using this for a form, I need to use TextFormField. Suggest me something.

Just add a listener to the TextEditingController.

something like below.

  @override
  void initState() {
    super.initState();

    _editingController.addListener(() {
      print(_editingController.text);
    });
  }

  @override
  void dispose() {
  // Clean up the controller when the Widget is disposed
  _editingController.dispose(); 
  super.dispose();
}

Hope it helps!

use the onChange(text) function of the TextFormField with a ValueNotifier, this should help you out.

TextFormField(
   controller: _Controller,
   label: "Input",
   currentNode: _Node,
   nextNode: FocusNode(),
   keyboard: TextInputType.visiblePassword,
   onChanged: (text) {
     _avalueNotifier.value = text;
   },
   inputFormatters: <TextInputFormatter>[                          
           BlacklistingTextInputFormatter.singleLineFormatter,
    ],
   validator: (String value) {
     if (value.isEmpty) {
        return 'Please make inputs';
     }
     return null;
     },
),

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