现在列之间有太多空间,即使我有4个字符的标题和1到3位的排名值,就好像我可以在每列中适合4倍。
我尝试使用较小的字体,但分离保持不变。
这是我用来设置PaginatedDataTable的内容。我无法在Table / Row / Cell / etc中找到任何看起来会影响宽度的参数。空间似乎是自动的,但完全没有必要。感谢。
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)
),...
答案 0 :(得分:1)
在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(),
),
答案 1 :(得分:0)
在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;
答案 2 :(得分:-1)
我也遇到了同样的问题,即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