忽略文本的onTap()事件->改为代替父行的onTap()事件

时间:2020-03-06 10:54:14

标签: flutter events textfield

我有一个Row小部件。该行的子级为Text(在本例中为SelectableText)。该行嵌入到InkWell小部件中,用于处理onTap()事件。除非我点击Text,否则此方法效果很好。在这种情况下,InkWell onTap()事件不会引发。

InkWell(
  child: Row (
    children: <Widget> [
      SelectableText(...)
    ]
  ),
  onTap: () => doSth();
)

是否可以忽略Text事件的onTap()事件?我的解决方法是使用相同的代码向onTap()添加一个Text事件。但是,实际上,我想避免这种复制。


编辑:实际上,Button小部件旁边还有一个Text小部件。尽管如此,其onPressed()事件仍应按预期运行。

InkWell(
  child: Row (
    children: <Widget> [
      SelectableText(...),
      Button(
        onPressed: () {...}
      )
    ]
  ),
  onTap: () => doSth();
)

2 个答案:

答案 0 :(得分:1)

使用IgnorePointer

InkWell(
  child: Row (
    children: <Widget> [
      IgnorePointer(
        child: SelectableText(...)
     )
    ]
  ),
  onTap: () => doSth();
)

答案 1 :(得分:0)

尝试一下:

GestureDetector(
 // behavior: HitTestBehavior.opaque,
  onTap: () => doSth();
  child: Row(
    children: <Widget>[
      SelectableText(...),
    ],
  ),
),
相关问题