代码:
Table(
children: [
TableRow(
children: [
Container(height: 100, color: Colors.red),
Container(color: Colors.green), // Read 'Q1' below.
Container(height: 100, color: Colors.blue),
],
),
],
)
Q1:如何将绿色容器高度拉伸到给定TableRow
的最大高度?
PS:为了简单起见,我为容器1和容器2提供了手动高度,但在现实世界中,我不知道它们的高度。其次,我知道我可以使用RenderBox
找到两个容器的高度,然后我可以找到(container1,container3(的最大值,并将其应用于第二个容器,但这将是太多的工作,我正在寻找更好的方法。
使用TableCell和TableCellVerticalAlignment.fill.
TableCell
:
一个小部件,用于控制如何对齐表的子级。TableCell小部件必须是表的子代,并且从TableCell小工具到其封闭表的路径必须仅包含TableRows、StatelessWidgets或StatefulWidgets(而不是其他类型的小部件,如RenderObjectWidgets(。
TableCellVerticalAlignment.fill
:
具有此对齐方式的单元格的大小与行一样高,然后使其适合行。
If all the cells have this alignment, then the row will have zero height.
Table(
children: [
TableRow(
children: [
Container(height: 100, color: Colors.red),
TableCell(
verticalAlignment: TableCellVerticalAlignment.fill,
child: Container(color: Colors.green),
),
Container(height: 100, color: Colors.blue),
],
),
],
)