首页 > 解决方案 > 检测 IgnorePointer 或 AbsorbPointer 内的某些小部件上的指针事件

问题描述

IgnorePointer例如,是否可以检测到 Flutter 内部或Flutter中某个 Widget 上的点击事件AbsorbPointer

代码示例:

AbsorbPointer(
  absorbing: *some condition to make it true or false*,
  child: ListView(
    children: [
      SomeButton(
        onTap: () => print("i want this method to run when this button is tapped even if absorbing is true"),
      ),
      ...
    ],
  ),
),

标签: flutter

解决方案


只是出于好奇,您为什么使用小部件只是为了拿走该小部件的主要功能我只是好奇?所以答案AbsorbPointer是肯定的,你可以包装一个小部件AbsorbPointerRawGestureDetector然后定义你自己的手势工厂来覆盖rejectGestures,这样它就可以接受所有手势,然后GestureArena仍然会注册点击。对于IgnorePointer此设置将不起作用。我想不出任何覆盖IgnorePointer.

SingleChildScrollView(
        physics: NeverScrollableScrollPhysics(),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
          //Column Content
          ],
        ),
      ),

你也可以换行AbsorbPointerListener因为这不使用GestureArena如果你想了解更多关于这个 Nash 写了一篇很棒的文章Flutter Deep Dive: Gestures


推荐阅读