这是我的数据表:
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
我希望表格的高度受到限制,以便您可以滚动浏览它,但水平方向的宽度应该是固定的,因此您无法滚动。如果内容不适合列,如上述错误所示,则文本不应从屏幕上消失,而是应进入第二行,以便屏幕上的两列都有足够的空间。我已经尝试了很多东西,但我根本无法限制表格的宽度,使其仅与父小部件一样宽。