DataTable constructor
- Key? key,
- required List<
DataColumn> columns, - int? sortColumnIndex,
- bool sortAscending = true,
- ValueSetter<
bool?> ? onSelectAll, - Decoration? decoration,
- MaterialStateProperty<
Color?> ? dataRowColor, - @Deprecated('Migrate to use dataRowMinHeight and dataRowMaxHeight instead. ' 'This feature was deprecated after v3.7.0-5.0.pre.') double? dataRowHeight,
- double? dataRowMinHeight,
- double? dataRowMaxHeight,
- TextStyle? dataTextStyle,
- MaterialStateProperty<
Color?> ? headingRowColor, - double? headingRowHeight,
- TextStyle? headingTextStyle,
- double? horizontalMargin,
- double? columnSpacing,
- bool showCheckboxColumn = true,
- bool showBottomBorder = false,
- double? dividerThickness,
- required List<
DataRow> rows, - double? checkboxHorizontalMargin,
- TableBorder? border,
- 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.
Implementation
DataTable({
super.key,
required this.columns,
this.sortColumnIndex,
this.sortAscending = true,
this.onSelectAll,
this.decoration,
this.dataRowColor,
@Deprecated(
'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.dataTextStyle,
this.headingRowColor,
this.headingRowHeight,
this.headingTextStyle,
this.horizontalMargin,
this.columnSpacing,
this.showCheckboxColumn = true,
this.showBottomBorder = false,
this.dividerThickness,
required this.rows,
this.checkboxHorizontalMargin,
this.border,
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);