I have a ListView where each item has its own onTap event. If I tap on an item while the list is idle (not scrolling), everything works fine, but if I tap an item immediately following a scroll motion, the GestureDetector doesn't receive anything, which makes the app feel unresponsive for users navigating quickly. Is there a way to prevent this behavior?
class _ScrollClickTestPageState extends State<ScrollClickTestPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Test"),
),
body: ListView.builder(
shrinkWrap: true,
itemCount: 20,
itemBuilder: (context,index) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => print("test: click detected"),
child: Container(
width: double.maxFinite,
height: 200,
color: ([...Colors.primaries]..shuffle()).first,
child: Center(
child: Text(
'$index',
style: Theme.of(context).textTheme.headline4,
),
),
),
);
}
),
);
}
}
Well I have working model for this issue:
Try below code:
Replace your onTap: () => print("test: click detected")
with onTap: () => {print("test: click detected")}
And boom your tap Gesture is working.