【发布时间】:2020-10-27 03:06:52
【问题描述】:
我的小部件区域是使用扩展容器创建的,例如:
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: Colors.blueGrey[200],
child: Text(
startTime,
textAlign: TextAlign.left,
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 16,
fontWeight: FontWeight.normal),
),
),
Expanded(
/* If this gesture detector is instantiated the tap is never found;
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => print("OnTap"),
*/
child:
Container(color: Colors.red[600]),
//),
), // Expanded
], // children
), // Column
如果上面的代码是用这个包裹的
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => print("OnTap"),
child: Container(
color: Colors.red[600],
child: // Code above
), // Container
), //GestureDetector
), // Expanded
那么 onTap 只注册在文本小部件中,而不会注册在最后一个展开的容器中。
检测没有在Container上触发,需要一个widget来填充待检测的空间是否正确?
编辑 我将扩展容器的手势检测更改为:
Expanded(
child: Material(
color: Colors.red[600],
child: InkWell(
onTap: () {print("InkWell");},
), // InkWell
), // Material
), // Expanded
而且水龙头仍然无法识别。
【问题讨论】:
-
你能显示 Column 的父小部件吗?和从 body 开始的代码,如果你使用的是脚手架?
-
@Anas Mohammed 我通过重写 Future Builder 解决了这个问题,返回一个 SpannableGrid 实例,更简洁。我应该删除问题还是添加自己的答案?代码是几百行代码,除了两周前我开始颤抖之外,没有人会从中学到任何东西?
-
由你决定。您可以编写一个解决方案来描述它为什么不起作用,或者如果您认为编写答案对任何人都没有帮助,那么您可以删除。