Flutter减少DataTable中DataRows之间的填充

时间:2019-05-28 14:17:47

标签: flutter flutter-layout

我希望它看起来如何(在->之后):

enter image description here

是否可以像这张图片那样做?

edit:就像Hugo所说的那样,通过将data_table.dart的代码复制到一个新文件中,更改了_dataRowHeight,并改为使用它来解决了这个问题。

3 个答案:

答案 0 :(得分:3)

不可能以简单的方式做到这一点。

DataTable是在DataRow内部定义的属性(如您所见,是私有的)。由于Widget不是Container,因此您也不能强制使其适合DataTable

最好的选择是复制DataTable的源代码以创建自己的_dataRowHeight,因此可以修改属性DataTable

扩展build()也是一种选择,但是您将不得不重写方法DataTable,并且仍然从"@types/react": "^16.8.17"复制很多内容。

答案 1 :(得分:2)

在Dart VM版本:2.7.0中,此问题已解决。您可以使用参数dataRowHeight解决您的问题。还有更多有用的参数:

DataTable({
Key key,
@required this.columns,
this.sortColumnIndex,
this.sortAscending = true,
this.onSelectAll,
this.dataRowHeight = kMinInteractiveDimension,
this.headingRowHeight = 56.0,
this.horizontalMargin = 24.0,
this.columnSpacing = 56.0,
this.showCheckboxColumn = true,
@required this.rows,  })

答案 2 :(得分:1)

快速浏览一下DataTable代码后,看起来填充是一个私有常量,用于该类中的某些私有构建方法。

static const double _tablePadding = 24.0;

如果确实需要使用DataTable小部件,则可以创建自己的扩展DataTable的类,然后重写其build函数以创建自己的_buildDataCell函数,并在其中提供自己的尺寸。

相关问题