我想你在找
FocusNode。
要收听焦点变化,您可以向添加一个列表器,
FocusNode并指定
focusNode到
TextField。
例:
class TextFieldFocus extends StatefulWidget { @override _TextFieldFocusState createState() => new _TextFieldFocusState();}class _TextFieldFocusState extends State<TextFieldFocus> { FocusNode _focus = new FocusNode(); TextEditingController _controller = new TextEditingController(); @override void initState() { super.initState(); _focus.addListener(_onFocusChange); } void _onFocusChange(){ debugPrint("Focus: "+_focus.hasFocus.toString()); } @override Widget build(BuildContext context) { return new Container( color: Colors.white, child: new TextField( focusNode: _focus, ), ); }}
希望能帮助到你!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)