如何更改Paginated DataTable上的列宽?

问题描述 投票:3回答:1

现在列之间有太多的空间,即使我有4个字符的标题和1到3位的排名值,就好像我可以在每列中适合4倍。

我尝试使用较小的字体,但分离保持不变。

这是我用来设置PaginatedDataTable的内容。我无法在Table / Row / Cell / etc中找到任何看起来会影响宽度的参数。空间似乎是自动的,但完全没有必要。谢谢。

enter image description here

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)
                    ),...
flutter
1个回答
-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

© www.soinside.com 2019 - 2024. All rights reserved.