我有一个 ListView,其中每个项目都有自己的 onTap 事件。如果我在列表空闲(不滚动)时点击一个项目,一切正常,但如果我在滚动动作后立即点击一个项目,则 GestureDetector 不会收到任何内容,这会使应用程序对快速导航的用户感到无响应. 有没有办法防止这种行为?
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,
),
),
),
);
}
),
);
}
}