Home > front end >  onTap not firing for ListView elements
onTap not firing for ListView elements

Time:12-31

I've got a ListView in which all the elements are wrapped with a GestureDetector. It seems onTap doesn't fire whilst the ListView is scrolled and is animating. It only fires when the list is perfectly still/doesn't move...

ListView.separated(
  itemCount: count,
  physics: BouncingScrollPhysics(),
  separatorBuilder: (context, _) => VSpace.xxl,
  itemBuilder: (ctx, idx) => GestureDetector(
    onTap: () {
      // DO somethihng
    },
    child: SomeChild(idx),
  ),
)

I vaguely remember seeing a GitHub issue about this some months ago but I can't find it.

CodePudding user response:

That's the expected behavior.

if the page is scrolling and you tap on the screen it stops the scrolling behavior first and then if you tapped on an item it will fire the gesture detector's onTap.

you can try in any other app and you will see this behavior, Facebook, Instagram, etc...

CodePudding user response:

If you want you to do something when user scrolls a ListView, you should use a Scroll Controller, see this link:

https://medium.com/@diegoveloper/flutter-lets-know-the-scrollcontroller-and-scrollnotification-652b2685a4ac

  • Related