How to hide soft input keyboard on flutter after clicking outside TextField/anywhere on screen?

后端 未结 16 1976
甜味超标
甜味超标 2020-12-08 01:54

Currently, I know the method of hiding the soft keyboard using this code, by onTap methods of any widget.

FocusScope.of(context).requestFocus(new         


        
16条回答
  •  眼角桃花
    2020-12-08 02:26

    You are doing it in the wrong way, just try this simple method to hide the soft keyboard. you just need to wrap your whole screen in the GestureDetector method and onTap method write this code.

            FocusScope.of(context).requestFocus(new FocusNode());
    

    Here is the complete example:

    new Scaffold(
    
    body: new GestureDetector(
      onTap: () {
       
        FocusScope.of(context).requestFocus(new FocusNode());
      },
    child: new Container(
       //rest of your code write here
        )
     )
    

提交回复
热议问题