how to dismiss keyboard flutter code example

Example 1: flutter unfocus textfield

FocusScope.of(context).unfocus();

Example 2: how to automatically close keyboard in flutter

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

Example 3: how i can close keyboard in flutter

class YourPage extends StatefulWidget {
  createState() => _YourPageState();
}

class _YourPageState extends State<MobileHome> {

  FocusNode focusNode = new FocusNode();
  
  Widget build(BuildContext context) {
  return Scaffold(
  	body: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        TextField(
          focusNode: focusNode,
        ),
        SizedBox(height: 10,),
        RaisedButton(child: Text("UP"),onPressed: (){
          FocusScope.of(context).requestFocus(focusNode);
        },),
        SizedBox(height: 10,),
        RaisedButton(child: Text("DOWN"),onPressed: (){
          focusNode.unfocus();
        },),    
      ],
    )
  );
  }
}

Example 4: how i can call keboard in flutter

class YourState extends StatelessWidget {  
FocusNode inputNode = FocusNode();
void openKeyboard(){
FocusScope.of(context).requestFocus(inputNode)
}


Widget build(BuildContext context) {
  return Scaffold(
  	body:Column(
    children:[
      TextFormField(
          focusNode: inputNode)
      )
      ...
      FlatButton(
          onpress:openKeyboard
      )
    ])
  )
}

Tags:

Dart Example