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

Flutter中如何让TableCell高度自适应填充父容器

自定义日历Widget:Table组件日期单元格高度自适应问题

我要创建一个自定义Calendar Widget,使用Table组件展示日期数字,示例结构如下:

MON.TUE.WED.THU.FRI.SAT.SUN.
1234567
891011121314
15161718192021
22232425262728
2930311234

我希望日期单元格能自适应高度以填充父容器,但一直无法实现。搜索相关方案没找到合适的,尝试用GridPane也没效果。以下是我使用Table的简化代码:

Expanded(
    child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 8.0),
        child: Table(
            children: rows
                .asMap()
                .map((index, row) {
                    return MapEntry(
                        index,
                        TableRow(
                            children: row.children!
                                .map((widget) => TableCell(
                                    verticalAlignment: TableCellVerticalAlignment.middle,
                                    child: widget,
                                ))
                                .toList(),
                           decoration: BoxDecoration(
                               border: Border(
                                   bottom: BorderSide(
                                       width: 1.0,
                                       color: Theme.of(context).colorScheme.onPrimary.withAlpha(80),
                                   )
                               )
                           ),
                         ),
                      );
                 })
                 .values
                 .toList(),
        ),
    ),
)

其中rows是包含所有TableRow的List<TableRow> rows = [];。

当前效果:
当前效果

期望效果:
期望效果

感谢帮助!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 22:20:13