You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中Expanded包裹的Stack子组件被其他Widget裁剪如何解决?

解决方案

Flutter中Stack组件默认开启了超出边界裁剪逻辑,你只需要给Stack配置clipBehavior属性为Clip.none即可关闭裁剪,超出Stack自身布局范围的内容也会正常渲染,符合你允许溢出提示的需求。

修改后的代码如下:

Container(
  padding: EdgeInsets.only(left: 16, right: 20, top: 16, bottom: 16),
  height: 68,
  width: 200,
  color: Colors.green,
  child: Row(
    children: [
      Expanded(
        child: Container(
          child: Stack(
            // 新增此行关闭自动裁剪
            clipBehavior: Clip.none,
            children: <Widget>[
              Positioned(
                left: 0,
                child: Container(
                  height: 36,
                  width: 60,
                  decoration: BoxDecoration(
                    color: Colors.black,
                    shape: BoxShape.circle,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
      SizedBox(
        width: 4,
      ),
      Container(
        width: 120,
        height: 30,
        color: Colors.red,
      ),
    ],
  ),
)

内容的提问来源于stack exchange,提问作者dontknowhy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 22:48:03