FlutterFirebase
FlutterFirebase

Reputation: 2353

Dismiss keyboard on scroll?

I have textfield in app. This open keyboard automatic when tap on textfield. But when scroll down on list (firebaseAnimatedList) behind it keyboard is not dismiss. This not normal and is big problem on iOS because cannot press back button to dismiss.

Anyone know how to solve?

Upvotes: 1

Views: 2642

Answers (4)

Fuad All
Fuad All

Reputation: 975

you can use keyboardDismissBehavior.

return ListView.builder(
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,

Upvotes: 3

user3532201
user3532201

Reputation: 639

This is what gives you the desired effect:

NotificationListener(
 onNotification: (ScrollNotification scrollInfo) {

   if (scrollInfo is ScrollUpdateNotification) {
     if (scrollInfo.scrollDelta >= 20.0)      {
       FocusScope.of(context).requestFocus(FocusNode());
      }
     }

    },
 child: new FirebaseAnimatedList ...)

Upvotes: 0

Fuxing Loh
Fuxing Loh

Reputation: 68

This is what I did:

NotificationListener(
  onNotification: (t) {
    if (t is UserScrollNotification) {
      FocusScope.of(context).requestFocus(FocusNode());
    }
  },
  child: ListView.builder(
    itemBuilder: (_, i) => Container(),
    itemCount: items.length,
  ),
);

Attaching a ScrollListener didn't work for me because Android uses ClampingScrollPhysics and it will only receive the scroll event if the ListView items are longer than the parent. However, a NotificationListener will receive all events bubbled up including UserScrollNotification.

Upvotes: 3

westdabestdb
westdabestdb

Reputation: 4648

You can put the following code in your lists scroll listener.

FocusScope.of(context).requestFocus(new FocusNode());

Upvotes: 0

Related Questions