现在,列之间有如此多的空间,即使我有一个4个字符的标题和1到3个用于排名的数字值,这就好像我可以在每一列中容纳4倍。
我尝试使用较小的字体,但分隔符保持不变。
下面是我用来设置PaginatedDataTable的代码。我在表格/行/单元格/等中找不到任何参数,看起来会影响宽度。这个空间看起来是自动的,但完全没有必要。谢谢。

Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: const Text('Tour Rankings')),
body:
new ListView(
padding: const EdgeInsets.all(5.0),
children: <Widget>[
new PaginatedDataTable(
header: const Text('Current Rankings'),
rowsPerPage: _rowsPerPage,
onRowsPerPageChanged: (int value) { setState(() { _rowsPerPage = value; }); },
sortColumnIndex: _sortColumnIndex,
sortAscending: _sortAscending,
columns: <DataColumn>[
new DataColumn(
label: new Text('Rank', style: new TextStyle(fontSize: 8.0)),
numeric: true,
onSort: (int columnIndex, bool ascending) => _sort<num>((Player d) => d.rank, columnIndex, ascending)
),
new DataColumn(
label: new Text('Prev', style: new TextStyle(fontSize: 8.0)),
numeric: true,
onSort: (int columnIndex, bool ascending) => _sort<num>((Player d) => d.prevRank, columnIndex, ascending)
),...发布于 2020-09-22 00:04:41
flutter中有一个分页数据表的属性为columnSpacing。根据材料设计规范,该值默认为56.0。
您可以根据需要更改该值,以更改列内容之间的水平边距。
PaginatedDataTable(
showCheckboxColumn: false,
columnSpacing: 10.0,
header: Center(
child: Text("Statement"),
),
columns: [
DataColumn(label: Text("Date")),
DataColumn(label: Text("Particular")),
DataColumn(label: Text("Debit")),
DataColumn(label: Text("Credit")),
DataColumn(label: Text("Detail")),
],
source: YourDataSource(),
),它应该看起来像这样:

发布于 2020-04-07 11:02:12
在this diff之后,您可以设置horizontalMargin和columnSpacing来实现自定义列宽。
/// The horizontal margin between the edges of the table and the content
/// in the first and last cells of each row.
///
/// When a checkbox is displayed, it is also the margin between the checkbox
/// the content in the first data column.
///
/// This value defaults to 24.0 to adhere to the Material Design specifications.
final double horizontalMargin;
/// The horizontal margin between the contents of each data column.
///
/// This value defaults to 56.0 to adhere to the Material Design specifications.
final double columnSpacing;发布于 2018-09-14 15:01:49
我在flutter PaginatedDataTable布局的灵活性方面也遇到了同样的问题。我的解决方案是使用布局变量扩展DataTable的构造函数:
FlexibleDataTable({
Key key,
@required this.columns,
this.sortColumnIndex,
this.sortAscending = true,
this.onSelectAll,
this.headingRowHeight = 56.0,
this.dataRowHeight = 48.0,
this.tablePadding = 24.0,
this.columnSpacing = 56.0,
this.sortArrowPadding = 2.0,
this.headingFontSize = 12.0,
@required this.rows,
}当然,我必须实现FlexiblePaginatedDatatable才能使用FlexibleDataTable:
new SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: new FlexibleDataTable(
key: _tableKey,
columns: widget.columns,
sortColumnIndex: widget.sortColumnIndex,
sortAscending: widget.sortAscending,
onSelectAll: widget.onSelectAll,
columnSpacing: 20.0,
dataRowHeight: 40.0,
rows: _getRows(_firstRowIndex, widget.rowsPerPage)
)
),Flutter团队应该在DataTable和PaginatedDataTable的官方版本中包含这个功能,这样其他人就不需要为这些琐碎的东西实现特别的版本。这个问题是存在的,我们将看到它何时会被解决。https://github.com/flutter/flutter/issues/12775
https://stackoverflow.com/questions/48230872
复制相似问题