Flutter DataTable

If you have fewer rows to display in a table, you can use DataTable.

DataTable is a materaial design data table where you can display a table with column labels and rows.

Note: Use DataTable if and only if you have fewer rows, because DataTable takes twice the computation for laying out elements on UI.

Syntax

Following is the syntax of a DataTable.

DataTable contains columns and rows. columns property takes array of DataColumn and rows property takes array of DataRow. Each DataRow has cells property that takes array of DataCell.

label property of DataColumn takes Widget as value. Also DataCell takes widget as a value. You can provide Text, Image, Icon, or any other widget.

Example

In the following example, we define a simple DataTable with three column labels and three rows.

main.dart

When you run this Flutter application, you would get the DataTable displayed in UI as shown below.

Flutter DataTable

Conclusion

In this Flutter Tutorial, we learned how to define DataTable and display a data table in Flutter UI.