DataTable class Null safety

A material design data table.

Displaying data in a table is expensive, because to lay out the table all the data must be measured twice, once to negotiate the dimensions to use for each column, and once to actually lay out the table given the results of the negotiation.

For this reason, if you have a lot of data (say, more than a dozen rows with a dozen columns, though the precise limits depend on the target device), it is suggested that you use a PaginatedDataTable which automatically splits the data into multiple pages.

This sample shows how to display a DataTable with three columns: name, age, and role. The columns are defined by three DataColumn objects. The table contains three rows of data for three example users, the data for which is defined by three DataRow objects.

To create a local project with this code sample, run:
flutter create --sample=material.DataTable.1 mysample

This sample shows how to display a DataTable with alternate colors per row, and a custom color for when the row is selected.
To create a local project with this code sample, run:
flutter create --sample=material.DataTable.2 mysample

DataTable can be sorted on the basis of any column in columns in ascending or descending order. If sortColumnIndex is non-null, then the table will be sorted by the values in the specified column. The boolean sortAscending flag controls the sort order.

See also:



DataTable({Key? key, required List<DataColumn> columns, int? sortColumnIndex, bool sortAscending: true, ValueSetter<bool?>? onSelectAll, Decoration? decoration, MaterialStateProperty<Color?>? dataRowColor, double? dataRowHeight, 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})
Creates a widget describing a data table. [...]


columns List<DataColumn>
The configuration and labels for the columns in the table.
columnSpacing double?
The horizontal margin between the contents of each data column. [...]
dataRowColor MaterialStateProperty<Color?>?
The background color for the data rows. [...]
dataRowHeight double?
The height of each row (excluding the row that contains column headings). [...]
dataTextStyle TextStyle?
The text style for data rows. [...]
decoration Decoration?
The background and border decoration for the table. [...]
dividerThickness double?
The width of the divider that appears between TableRows. [...]
hashCode int
The hash code for this object. [...]
@nonVirtual, read-only, inherited
headingRowColor MaterialStateProperty<Color?>?
The background color for the heading row. [...]
headingRowHeight double?
The height of the heading row. [...]
headingTextStyle TextStyle?
The text style for the heading row. [...]
horizontalMargin double?
The horizontal margin between the edges of the table and the content in the first and last cells of each row. [...]
key Key?
Controls how one widget replaces another widget in the tree. [...]
final, inherited
onSelectAll ValueSetter<bool?>?
Invoked when the user selects or unselects every row, using the checkbox in the heading row. [...]
rows List<DataRow>
The data to show in each row (excluding the row that contains the column headings). [...]
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
showBottomBorder bool
Whether a border at the bottom of the table is displayed. [...]
showCheckboxColumn bool
Whether the widget should display checkboxes for selectable rows. [...]
sortAscending bool
Whether the column mentioned in sortColumnIndex, if any, is sorted in ascending order. [...]
sortColumnIndex int?
The current primary sort key's column. [...]


build(BuildContext context) Widget
Describes the part of the user interface represented by this widget. [...]
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree. [...]
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
toString({DiagnosticLevel minLevel:}) String
A string representation of this object. [...]
toStringDeep({String prefixLineOne: '', String? prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants. [...]
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object. [...]
toStringShort() String
A short, textual description of this widget.


operator ==(Object other) bool
The equality operator. [...]
@nonVirtual, inherited