gpt4 book ai didi

Flutter DataTable 删除额外的填充

转载 作者:IT王子 更新时间:2023-10-29 06:45:25 24 4
gpt4 key购买 nike

我想在 DataTable 中显示一些数据,我有 9 列,除了第一列之外都是数字。

我遇到的问题是,我只看到前 5 列,不是因为数据太长,而是因为每列之间有很多空间。

enter image description here

有没有办法让 DataColumn 用我选择的填充来包装数据?这是我的代码:

Scaffold(
appBar: AppBar(
title: Text('DataTable Sample'),
),
body: Container(
child: DataTable(columns: <DataColumn>[
DataColumn(
label: Text('Name'),
),
DataColumn(
label: Text('A'),
),
DataColumn(
label: Text('B'),
),
DataColumn(
label: Text('C'),
),
DataColumn(
label: Text('D'),
),
DataColumn(
label: Text('E'),
),
DataColumn(
label: Text('F'),
),
DataColumn(
label: Text('G'),
),
DataColumn(
label: Text('H'),
),
], rows: <DataRow>[
DataRow(cells: [
DataCell(Text('1 Boston')),
DataCell(Text('3')),
DataCell(Text('3')),
DataCell(Text('7')),
DataCell(Text('1')),
DataCell(Text('30')),
DataCell(Text('8')),
DataCell(Text('+2')),
DataCell(Text('-22')),
]),
DataRow(cells: [
DataCell(Text('2 London')),
DataCell(Text('3')),
DataCell(Text('4')),
DataCell(Text('12')),
DataCell(Text('44')),
DataCell(Text('7')),
DataCell(Text('44')),
DataCell(Text('-98')),
DataCell(Text('0')),
]),
DataRow(cells: [
DataCell(Text('3 Rome')),
DataCell(Text('10')),
DataCell(Text('50')),
DataCell(Text('90')),
DataCell(Text('4')),
DataCell(Text('7')),
DataCell(Text('33')),
DataCell(Text('+5')),
DataCell(Text('-61')),
]),
]
)
),
);

最佳答案

您可以使用 SingleChildScrollViewFittedBox 作为它的 child 。

Scaffold(
appBar: AppBar(
title: Text('DataTable Sample'),
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: FittedBox(
child: DataTable(
columns: <DataColumn>[
DataColumn(
label: Text('Name'),
),
DataColumn(
label: Text('A'),
),
DataColumn(
label: Text('B'),
),
DataColumn(
label: Text('C'),
),
DataColumn(
label: Text('D'),
),
DataColumn(
label: Text('E'),
),
DataColumn(
label: Text('F'),
),
DataColumn(
label: Text('G'),
),
DataColumn(
label: Text('H'),
),
],
rows: <DataRow>[
DataRow(cells: [
DataCell(Text('1 Boston')),
DataCell(Text('3')),
DataCell(Text('3')),
DataCell(Text('7')),
DataCell(Text('1')),
DataCell(Text('30')),
DataCell(Text('8')),
DataCell(Text('+2')),
DataCell(Text('-22')),
]),
DataRow(cells: [
DataCell(Text('2 London')),
DataCell(Text('3')),
DataCell(Text('4')),
DataCell(Text('12')),
DataCell(Text('44')),
DataCell(Text('7')),
DataCell(Text('44')),
DataCell(Text('-98')),
DataCell(Text('0')),
]),
DataRow(cells: [
DataCell(Text('3 Rome')),
DataCell(Text('10')),
DataCell(Text('50')),
DataCell(Text('90')),
DataCell(Text('4')),
DataCell(Text('7')),
DataCell(Text('33')),
DataCell(Text('+5')),
DataCell(Text('-61')),
]),
],
),
),
),
);

关于Flutter DataTable 删除额外的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55271153/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com