Flutter踩坑记录(二)-- GestureDetector+Expanded点击无效果

Expanded是自动扩展布局,它可以用于Row, Column或Flex布局中。Expanded部件会尝试占用尽可能多的空间。

但是在GestureDetector中,点击事件会无效:

解决方法

给GestureDetector包裹的最外层Widget加一个背景色:

复制代码
GestureDetector(
      onTap: onTap,
      child: Container(
        color: Colors.transparent,
        height: 50,
        margin: const EdgeInsets.only(left: 10, right: 10),
        child: Stack(
          alignment: Alignment.center,
          children: [
            Row(
              children: <Widget>[
                Image.asset(image),
                Container(
                  margin: const EdgeInsets.only(left: 10),
                  child: Text(
                    title,
                    style: const TextStyle(fontSize: 16),
                  ),
                ),
                Expanded(child: Container()), //自动扩展挤压
                Image.asset(
                  'assets/images/community_icon_right.png',
                  width: 20,
                )
              ],
            ),
          ],
        ),
      ),
    );
相关推荐
java1234_小锋2 小时前
【技术专题】HTML5 网页技术 - HTML5 Canvas 基础以及动画入门
前端·html·html5
知了学历孙老师5 小时前
小自考的校考和统考,出题方和难度差在哪
java·大数据·前端
ShineWinsu7 小时前
对于JavaScript:操作元素的解析
开发语言·前端·javascript·面试·web·dom·元素
福兮说7 小时前
JSON 格式正确,数据就可靠吗?我用一份自编配置检查类型与空值
java·前端·json
程序员老赵9 小时前
Docker 部署青龙面板:轻松搭建定时任务管理平台
前端·docker·开源
Swot9 小时前
Asciidoctor 公式数字下标错位问题:原因分析与解决方案
前端
Swot9 小时前
leo-editor 中将 Markdown 内容转成 asciidoc 格式
前端
狒狒AI10 小时前
Remotion / GSAP+Three / HyperFrames / Skia 四栈实测:代码渲染知识视频的选栈方法(附开源技能)
前端·人工智能·aigc
修炼的dance10 小时前
浏览器里导出H.265,8.5秒和55.5秒差在硬件
前端
补码缩写10 小时前
WebCodecs选编码器,探测之后还要验解码和播放
前端