Hem*_*Raj 33
您可以指定控制器和焦点节点,然后向其添加侦听器以监视更改.
例如:
定义控制器和焦点节点
TextEditingController _controller = new TextEditingController();
FocusNode _textFocus = new FocusNode();
Run Code Online (Sandbox Code Playgroud)
定义监听器功能
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
);
}
Run Code Online (Sandbox Code Playgroud)
将listner添加到控制器并将焦点定位到 initState
// you can have different listner functions if you wish
_controller.addListener(onChange);
_textFocus.addListener(onChange);
Run Code Online (Sandbox Code Playgroud)
然后你可以用它
new TextFormField(
controller: _controller,
focusNode: _textFocus,
)
Run Code Online (Sandbox Code Playgroud)
希望有所帮助!
| 归档时间: |
|
| 查看次数: |
15909 次 |
| 最近记录: |