Mobile 颤振文本表单字段如何添加手动onChange属性

Mobile 颤振文本表单字段如何添加手动onChange属性,mobile,dart,flutter,Mobile,Dart,Flutter,我将TextEditingController添加到我的TextFormField以读取用户输入,但我希望在TextFormField中的每次更新时读取输入,并且控制器显示以前的更新。简而言之,我想要一个类似于TextField中onChanged方法的替代方法,因为我将其用于表单,所以我需要使用TextFormField。给我一些建议。只需在TextEditingController中添加一个侦听器 像下面这样 @override void initState() { supe

我将TextEditingController添加到我的TextFormField以读取用户输入,但我希望在TextFormField中的每次更新时读取输入,并且控制器显示以前的更新。简而言之,我想要一个类似于TextField中onChanged方法的替代方法,因为我将其用于表单,所以我需要使用TextFormField。给我一些建议。

只需在TextEditingController中添加一个侦听器

像下面这样

  @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();
}
希望有帮助

将TextFormField的onChange(text)函数与ValueNotifier一起使用,这应该会对您有所帮助

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;
     },
),
TextFormField(
控制器:_控制器,
标签:“输入”,
currentNode:_节点,
nextNode:FocusNode(),
键盘:TextInputType.visiblePassword,
一旦更改:(文本){
_avalueNotifier.value=文本;
},
输入格式化程序:[
BlacklistingOutputFormatter.singleLineFormatter,
],
验证器:(字符串值){
if(value.isEmpty){
返回“请输入”;
}
返回null;
},
),

添加一些详细信息。。。一些代码,例如…还应该调用_editingController.dispose();在处理方法上。谢谢你曾经为我工作过。我动态创建textformfields列表,因此textcontroller不是获取textformfield数据的选项。