How can I dismiss the on screen keyboard?

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

    To dismiss the keyboard (1.7.8+hotfix.2 and above) just call the method below:

    FocusScope.of(context).unfocus();
    

    Once the FocusScope.of(context).unfocus() method already check if there is focus before dismiss the keyboard it's not needed to check it. But in case you need it just call another context method: FocusScope.of(context).hasPrimaryFocus

提交回复
热议问题