【发布时间】:2020-12-17 00:10:37
【问题描述】:
使用 Flutter v1.20.2
以下代码
var data = [
['a', 'VerylongstringwithnospacesVerylongstringwithnospaces'],
['abc', '123456789'],
['abcdefg', '123'],
];
Expanded(
child: Table(
border: TableBorder.all(color: Colors.red),
columnWidths: {
0: IntrinsicColumnWidth(),
1: IntrinsicColumnWidth(),
},
children: data.map<TableRow>((x) => (
TableRow(
children: <TableCell>[
TableCell(child: Container(child: Text(x[0]))),
TableCell(child: Container(color: Colors.green, child: Text(x[1]))),
],
)
)).toList(),
),
),
这个布局的结果
如你所见,文字超出了表格的边界。
我尝试了无数的解决方案,但都没有奏效。与表格列的大小相比,TableCell 本身的宽度似乎大于应有的宽度。
最大的问题是两列的大小是未知的,它们可能是数百个字符或单个字母。如果它大于宽度,文本应该换到下一行。
有没有办法制作一个流畅的网格布局,以便两边都根据每列的内容量调整大小?理想的布局应该是这样的
【问题讨论】: