Flutter中如何让TableCell高度自适应填充父容器
自定义日历Widget:Table组件日期单元格高度自适应问题
我要创建一个自定义Calendar Widget,使用Table组件展示日期数字,示例结构如下:
| MON. | TUE. | WED. | THU. | FRI. | SAT. | SUN. |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 1 | 2 | 3 | 4 |
我希望日期单元格能自适应高度以填充父容器,但一直无法实现。搜索相关方案没找到合适的,尝试用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
相关产品推荐
相关产品推荐

