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

Expanded是自动扩展布局,它可以用于Row, ColumnFlex布局中。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,
                )
              ],
            ),
          ],
        ),
      ),
    );
相关推荐
haogexiaole1 小时前
vue知识点总结
前端·javascript·vue.js
哆啦A梦15883 小时前
[前台小程序] 01 项目初始化
前端·vue.js·uni-app
智码看视界4 小时前
老梁聊全栈系列:(阶段一)架构思维与全局观
java·javascript·架构
小周同学@6 小时前
谈谈对this的理解
开发语言·前端·javascript
Wiktok6 小时前
Pyside6加载本地html文件并实现与Javascript进行通信
前端·javascript·html·pyside6
一只小风华~6 小时前
Vue:条件渲染 (Conditional Rendering)
前端·javascript·vue.js·typescript·前端框架
柯南二号6 小时前
【大前端】前端生成二维码
前端·二维码
程序员码歌7 小时前
明年35岁了,如何破局?说说心里话
android·前端·后端
博客zhu虎康7 小时前
React Hooks 报错?一招解决useState问题
前端·javascript·react.js
灰海8 小时前
vue中通过heatmap.js实现热力图(多个热力点)热区展示(带鼠标移入弹窗)
前端·javascript·vue.js·heatmap·heatmapjs