这是我的数据表格:
例外情况是:
SizedBox(
height: 200,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: DataTable(
columnSpacing: 0,
columns: const [
DataColumn(label: Text("Domain")),
DataColumn(label: Text("Request count")),
],
rows: const [
DataRow(cells: [
DataCell(Text("A very long text which causes the right column to be pushed out of the screen")),
DataCell(Text("12345")),
]),
DataRow(cells: [
DataCell(Text("It would be the best if this text would be shown in to lines so that there is enough space for the second column")),
DataCell(Text("678890")),
]),
],
),
),
)
例外情况是:
The following assertion was thrown during layout:
A RenderFlex overflowed by 39 pixels on the right.
The relevant error-causing widget was
DataTable
我希望表格的高度受限,这样你就可以通过滚动来查看它,但是水平方向的宽度应该是固定的,这样你就无法滚动。如果内容不能适应列中,就像上面的错误显示的那样,那么文本不应该从屏幕上消失,而是应该进入第二行,这样屏幕上就有足够的空间容纳两列。我已经尝试了很多方法,但我无法将表格的宽度限制为与父部件一样宽。