skip to Main Content

Keyboard is not dismissing correctly in fl;utter using keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag, property inside a singleChildScrollview , when drawer is opened.

need to dismiss the keyboard when drawer is opened

https://github.com/flutter/flutter/assets/90414446/911db935-9a95-466d-9d51-26312ad856e3

2

Answers


  1. Have you tried FocusManager.instance.primaryFocus?.unfocus()

    By adding this on drawer open event.

    Login or Signup to reply.
  2. It handles the scenario where the drawer is already open by unfocusing other widgets to avoid conflicts.

    GestureDetector(
      onTap: () {
        if (Scaffold.of(context).isDrawerOpen) {
          FocusScope.of(context).unfocus();
        }
      },
      child: Scaffold(
        body: SingleChildScrollView(
          keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
          child: YourChildWidget(),
        ),
      ),
    ),
    

    if this is not work so use FocusNode like.

    FocusNode _focusNode = FocusNode();
    
    GestureDetector(
      onTap: () {
        if (Scaffold.of(context).isDrawerOpen) {
               _focusNode.unfocus();
            }
          },
      child: Scaffold(
        body: SingleChildScrollView(
          keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
          child: YourChildWidget(
            focusNode: _focusNode,
          ),
        ),
      ),
    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search