DataTable constructor

  1. {Key? key,
  2. required List<DataColumn> columns,
  3. int? sortColumnIndex,
  4. bool sortAscending = true,
  5. ValueSetter<bool?>? onSelectAll,
  6. Decoration? decoration,
  7. MaterialStateProperty<Color?>? dataRowColor,
  8. @Deprecated('Migrate to use dataRowMinHeight and dataRowMaxHeight instead. ' 'This feature was deprecated after v3.7.0-5.0.pre.') double? dataRowHeight,
  9. double? dataRowMinHeight,
  10. double? dataRowMaxHeight,
  11. TextStyle? dataTextStyle,
  12. MaterialStateProperty<Color?>? headingRowColor,
  13. double? headingRowHeight,
  14. TextStyle? headingTextStyle,
  15. double? horizontalMargin,
  16. double? columnSpacing,
  17. bool showCheckboxColumn = true,
  18. bool showBottomBorder = false,
  19. double? dividerThickness,
  20. required List<DataRow> rows,
  21. double? checkboxHorizontalMargin,
  22. TableBorder? border,
  23. Clip clipBehavior = Clip.none}

Creates a widget describing a data table.

The columns argument must be a list of as many DataColumn objects as the table is to have columns, ignoring the leading checkbox column if any. The columns argument must have a length greater than zero.

The rows argument must be a list of as many DataRow objects as the table is to have rows, ignoring the leading heading row that contains the column headings (derived from the columns argument). There may be zero rows, but the rows argument must not be null.

Each DataRow object in rows must have as many DataCell objects in the DataRow.cells list as the table has columns.

If the table is sorted, the column that provides the current primary key should be specified by index in sortColumnIndex, 0 meaning the first column in columns, 1 being the next one, and so forth.

The actual sort order can be specified using sortAscending; if the sort order is ascending, this should be true (the default), otherwise it should be false.


  required this.columns,
  this.sortAscending = true,
    'Migrate to use dataRowMinHeight and dataRowMaxHeight instead. '
    'This feature was deprecated after v3.7.0-5.0.pre.',
  double? dataRowHeight,
  double? dataRowMinHeight,
  double? dataRowMaxHeight,
  this.showCheckboxColumn = true,
  this.showBottomBorder = false,
  required this.rows,
  this.clipBehavior = Clip.none,
}) : assert(columns.isNotEmpty),
     assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)),
     assert(!rows.any((DataRow row) => row.cells.length != columns.length), 'All rows must have the same number of cells as there are header cells (${columns.length})'),
     assert(dividerThickness == null || dividerThickness >= 0),
     assert(dataRowMinHeight == null || dataRowMaxHeight == null || dataRowMaxHeight >= dataRowMinHeight),
     assert(dataRowHeight == null || (dataRowMinHeight == null && dataRowMaxHeight == null),
       'dataRowHeight ($dataRowHeight) must not be set if dataRowMinHeight ($dataRowMinHeight) or dataRowMaxHeight ($dataRowMaxHeight) are set.'),
     dataRowMinHeight = dataRowHeight ?? dataRowMinHeight,
     dataRowMaxHeight = dataRowHeight ?? dataRowMaxHeight,
     _onlyTextColumn = _initOnlyTextColumn(columns);