How can I dismiss the on screen keyboard?

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

    For me, the Listener above App widget is the best approach I've found:

    Listener(
      onPointerUp: (_) {
        FocusScopeNode currentFocus = FocusScope.of(context);
        if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
          currentFocus.focusedChild.unfocus();
        }
      },
      child: MaterialApp(
        title: 'Flutter Test App',
        theme: theme,
        ...
      ),
    )
    

提交回复
热议问题