您可以指定一个控制器和焦点节点,然后向其添加侦听器以监视更改。
例如:
定义控制器和焦点节点
TextEditingController _controller = new TextEditingController();FocusNode _textFocus = new FocusNode();
定义监听器功能
void onChange(){ String text = _controller.text; bool hasFocus = _textFocus.hasFocus; //do your text transforming _controller.text = newText; _controller.selection = new TextSelection( baseOffset: newText.length,extentOffset: newText.length );}将listner添加到控制器和focusnode处
initState
// you can have different listner functions if you wish_controller.addListener(onChange); _textFocus.addListener(onChange);
然后您可以将其用作
new TextFormField( controller: _controller, focusNode: _textFocus,)
希望有帮助!



