防止触摸事件到达父窗口小部件

时间:2019-11-13 18:00:07

标签: flutter flutter-layout flutter-widget

在下面的示例中,当单击FlatButton时,触摸事件也被扩展到InkWell,显示波纹。有没有办法禁用这种行为?那么,如果子部件消耗了触摸,它就不会到达部件的父级吗?

InkWell(
      onTap: () {},
      child: Row(
        children: <Widget>[
          Text("Dummy text"),
          FlatButton(onPressed: () {}, child: Text("Button"))
        ],
      ),
    );

2 个答案:

答案 0 :(得分:0)

该事件未到达父窗口小部件。扁平按钮默认情况下具有波纹效果。您可以禁用它,将FlatButton的splashColor设置为透明。可以对InkWell做同样的事情。

InkWell(
      splashColor: Colors.transparent,
      highlightColor: Colors.transparent,
      onTap: () {},
      child: Row(
        children: <Widget>[
          Text("Dummy text"),
          FlatButton(
           splashColor: Colors.transparent,
           onPressed: () {}, child: Text("Button"))
        ],
      ),
);

答案 1 :(得分:0)

我知道为时已晚,但是如果有人在寻找正确的答案。在这里。

InkWell(
  onTap: () {},
  child: Row(
    children: <Widget>[
      Text("Dummy text"),
      FlatButton(onPressed: () {
        FocusScope.of(context).requestFocus();
      }, child: Text("Button")),
    ],
  ),
);

FocusScope.of(context).requestFocus()将使按钮请求焦点,这样InkWell不会显示波纹。

相关问题