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

Flutter中Container无法占满父组件宽度问题求助

解决红色Container占满父组件宽度的问题

你的问题根源在于Row右侧的Column没有占据Row的剩余宽度,导致里面的红色Container无法撑满宽度。按以下步骤修改即可:

  • 给右侧的Column外层包裹Expanded组件,让它填充Row的剩余空间
  • 给红色Container添加width: double.infinite,使其占满Column的宽度

修改后的完整代码如下:

child: ListView.builder(
  itemCount: series?.length,
  scrollDirection: Axis.vertical,
  shrinkWrap: true,
  itemBuilder: (item, index) {
    return Container(
      clipBehavior: Clip.hardEdge,
      margin: const EdgeInsets.only(bottom: 15),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20),
        border: Border.all(
            color: const Color.fromRGBO(205, 205, 205, 1)),
        boxShadow: [
          BoxShadow(
            color: Color.fromARGB(255, 216, 216, 216)
                .withOpacity(0.5),
            spreadRadius: 2,
            blurRadius: 3,
            offset: Offset(0, 3), // 改变阴影位置
          ),
        ],
      ),
      child: Row(
        children: [
          Container(
              width: 100,
              height: 150,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(78),
              ),
              child: Container(
                decoration: const BoxDecoration(
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(8),
                      bottomLeft: Radius.circular(8)),
                ),
                child: Image.network(
                  series![index].thumbUrl,
                  fit: BoxFit.cover,
                ),
              )),
          // 用Expanded包裹Column,使其占据Row剩余宽度
          Expanded(
            child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Container(
                      color: Color.fromARGB(255, 83, 30, 30),
                      width: double.infinite, // 设置宽度占满父组件
                      height: 150,
                      child: Text("hhh"))
                ]),
          )
        ],
      ),
    );
  }),

另外注意:你代码里的BorderRadius.circular(078)是无效写法,0开头的数字在Dart中属于八进制数,而78不是合法的八进制数字,建议改为BorderRadius.circular(78)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 07:35:26