@override Widget build(BuildContext context) { //创建FocusNode对象实例 FocusNode focusNode = FocusNode(); //添加监听器 focusNode.addListener(() { //输出当前焦点状态 print("当前状态---${focusNode.hasFocus}"); }); return Scaffold( appBar: AppBar( title: Text('HomeView'), centerTitle: true, ), //GestureDetector 手势监听控件 body: InkWell( onTap: () { //隐藏键盘 // SystemChannels.textInput.invokeMethod('TextInput.hide'); //获取焦点 FocusScope.of(context).requestFocus(FocusNode()); //隐藏键盘而不丢失文本字段焦点: // FocusScope.of(context).unfocus(); }, child: Column( children: [ TextField( focusNode: focusNode, ), ], ), ), ); }
THE END