jxmorris12
jxmorris12

Reputation: 1372

Scrolling a ListView inside a GestureDetector

I'm trying to detect when a ListView is scrolled so that I can dismiss the keyboard at that time.

Currently, I have my ListView wrapped in a GestureDetector. The onVerticalDragStart of the gesture detector is set to dismiss the keyboard. However, when I intercept the event like this, it is preventing the drag event from bubbling downward to the ListView so I can't actually scroll the view anymore.

I tried setting behavior: HitTestBehavior.translucent on the GestureDetector but for some reason this didn't do what I wanted. How can I achieve this behavior without subclassing ListView?

Upvotes: 1

Views: 4385

Answers (2)

Collin Jackson
Collin Jackson

Reputation: 116708

I would wrap the ListView in a NotificationListener instead of a GestureDetector.

Upvotes: 0

Abhi Agarwal
Abhi Agarwal

Reputation: 521

Instead of wrapping the ListView in a GestureDetector, why don't you just add a listener (via the method addListener) to a ScrollController (assuming you already aren't using one) that calls a VoidCallback every time the state changes?

Upvotes: 4

Related Questions