How can I dismiss the on screen keyboard?

前端 未结 18 2313
星月不相逢
星月不相逢 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 18:58

    _dismissKeyboard(BuildContext context) {
       FocusScope.of(context).requestFocus(new FocusNode());
    }
    
    @override
    Widget build(BuildContext context) {
    
    return new GestureDetector(
        onTap: () {
        this._dismissKeyboard(context);
        },
        child: new Container(
        color: Colors.white,
        child: new Column(
            children: [/*...*/],
        ),
        ),
     );
    }
    

提交回复
热议问题