我正在尝试击中最上面可见的物体后面的物体。我试图通过使用 的属性来实现这GestureDetector
一点behavior
。
其代码如下:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new GestureDetector(
onTap: () => print("Bottom"),
child: new Container(
color: Colors.redAccent,
child: new Center(
child: new GestureDetector(
onTap: () => print("Top"),
behavior: HitTestBehavior.translucent,
child: new Container(
width: 200.0,
height: 200.0,
color: Colors.blue.withOpacity(0.3),
),
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这似乎不起作用。只有Top会打印到控制台。文档看起来这是正确的做法,但也许我在这里遗漏了一些东西?
\n\n\n我希望底部的一个或两个都接收该
\nonTap
事件。
如果只获取Bottom
事件就可以了,那么只需删除:
onTap: () => print("Top"),\n
Run Code Online (Sandbox Code Playgroud)\n\n对我有用。注释掉该行后,Bottom
当我点击内部方块时,它就会打印出来。
用这个版本测试过:
\n\nDannys-MacBook:flutter danny$ flutter --version\nFlutter 0.4.5-pre.96 \xe2\x80\xa2 channel master \xe2\x80\xa2 https://github.com/DanTup/flutter.git\nFramework \xe2\x80\xa2 revision d79f2ee223 (12 hours ago) \xe2\x80\xa2 2018-05-26 12:29:53 -0700\nEngine \xe2\x80\xa2 revision 1ed25ca7b7\nTools \xe2\x80\xa2 Dart 2.0.0-dev.58.0.flutter-f981f09760\n
Run Code Online (Sandbox Code Playgroud)\n\n也就是说,删除内部的GestureDetector
效果相同,所以我想知道您添加它是否有某种原因?
归档时间: |
|
查看次数: |
5152 次 |
最近记录: |