如何解决扩展容器中的手势检测
我的小部件的一个区域是使用扩展容器创建的,例如:
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,child: Container(
color: Colors.red[600],child: // Code above
),// Container
),//GestureDetector
),// Expanded
然后onTap仅注册在文本小部件中,而不注册在最后一个扩展的容器中。
检测是否不会在Container上触发并且需要一个小部件来填充要检测的空间是否正确?
修改 我将扩展容器的手势检测更改为:
Expanded(
child: Material(
color: Colors.red[600],child: InkWell(
onTap: () {print("InkWell");},// InkWell
),// Material
),// Expanded
仍然无法识别点击。
解决方法
第一段代码应该可以正常工作,我认为您在代码的另一部分遇到错误,请提供完整的代码吗?以及您在控制台中得到的内容。
这是您在DartPad中完全可用的代码段:https://dartpad.dev/f76d383475c5c7c35ca4bf59b0a83789
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。