Flutter中Stack内Positioned组件下的InkWell点击无响应如何解决?
Flutter Stack中InkWell点击失效解决方案
核心问题:错误使用IgnorePointer组件
你的代码中InkWell的直接子组件为IgnorePointer,该组件的作用是拦截自身及所有子节点的点击事件,直接移除该组件即可恢复点击,修改后的对应代码如下:
Container( width: 200, height: 200, padding: const EdgeInsets.only(top: 50), child: InkWell( onTap: () { print('click'); }, // 移除IgnorePointer层,直接放置子组件 child: Center( child: Text( "voir plus (96 autres contacts)", style: bTextInfoItemBottomSearchCard ) ), ), )
其余可能的触发原因
如果移除后仍然无法点击,可按以下方向排查:
- Stack组件自身尺寸未覆盖Positioned子组件的区域:
clipBehavior: Clip.none仅能让超出Stack尺寸的内容正常渲染,超出Stack本身尺寸的区域无法响应点击事件,需要给Stack设置足够的宽高,保证Positioned对应的组件完全在Stack的尺寸范围内。 - InkWell缺少Material祖先节点:InkWell的事件触发和涟漪效果依赖上层存在Material组件,若当前组件树往上没有Scaffold、Card等自带Material的组件,可给InkWell套一层透明背景的Material:
child: Material( color: Colors.transparent, child: InkWell( // 原有InkWell配置 ), )
内容的提问来源于stack exchange,提问作者gbeto Jean-José
相关产品推荐
相关产品推荐

