How can I dismiss the on screen keyboard?

前端 未结 18 2324
星月不相逢
星月不相逢 2020-11-30 18:31

I am collecting user input with a TextFormField and when the user presses a FloatingActionButton indicating they are done, I want to dismiss the on

18条回答
  •  一向
    一向 (楼主)
    2020-11-30 19:02

    None of the above solutions don't work for me.

    Flutter suggests this - Put your widget inside new GestureDetector() on which tap will hide keyboard and onTap use FocusScope.of(context).requestFocus(new FocusNode())

    class Home extends StatelessWidget {
    @override
      Widget build(BuildContext context) {
        var widget = new MaterialApp(
            home: new Scaffold(
                body: new Container(
                    height:500.0,
                    child: new GestureDetector(
                        onTap: () {
                            FocusScope.of(context).requestFocus(new FocusNode());
                        },
                        child: new Container(
                            color: Colors.white,
                            child:  new Column(
                                mainAxisAlignment:  MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
    
                                children: [
                                    new TextField( ),
                                    new Text("Test"),                                
                                ],
                            )
                        )
                    )
                )
            ),
        );
    
        return widget;
    }}
    

提交回复
热议问题