【问题标题】:GestureDetector does not receive events while scrollingGestureDetector 在滚动时不接收事件
【发布时间】:2021-06-17 00:18:15
【问题描述】:

我有一个 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,
                ),
              ),
            ),
          );
        }
      ),
    );
  }

}

【问题讨论】:

    标签: flutter gesturedetector flutter-listview flutter-onpressed


    【解决方案1】:

    嗯,我有这个问题的工作模型: 试试下面的代码: 替换你的onTap: () =&gt; print("test: click detected")onTap: () =&gt; {print("test: click detected")} 并且繁荣你的水龙头手势工作。

    【讨论】:

    • 不,我仍然遇到与我最初发布的代码相同的问题。如果列表视图没有滚动,则接收点击,但如果它正在滚动,则忽略。
    • 所以我认为这实际上不会在任何应用程序中正常发生。 Bcz 一次只有一个手势有效。
    • 你是对的,即使是原生 iOS 和 Android 应用程序似乎也有相同的行为。我想这就是可滚动的工作方式。
    猜你喜欢
    • 2023-03-27
    • 2014-08-22
    • 1970-01-01
    • 2014-07-31
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 2021-03-07
    相关资源
    最近更新 更多