Create a Data Table in Flutter

Updated 20 December 2023

Save

Flutter comes with its UI toolkit full of many widgets that do various things. One such widget Flutter offers is the DataTable widget to display tabular data structures. The Data Table in Flutter is very flexible compared to the native platform-specific list views.

For Mobile app developers, displaying data is an everyday task. We also need to display data in tables by laying out all the rows & columns with appropriate needed space for the same. Data tables are easy to understand. It also helps users to categorize the data. Data Tables in Flutter also help to show & understand more data in less space.

Read more about the Flutter app development Services that Mobikul offers.

Let’s check how can we implement DataTable in Flutter.

Add Data Table Widget:

Create a Data table by adding a Data Table widget & add decoration using the Table Border widget.

Define Data Columns:

Add Data columns in the Data Table column property:

Define rows & data cells:

Create Data rows and add data cells to them.

We can use its different properties for different purposes. I want to select the row by tapping on it. Let’s check how can we select a row.

Show selected row:

selected: It’s a property that takes a boolean value & shows if the row is selected or not.

onSelectChanged: It is called when the user selects or unselects a selectable row

Define an integer selectedIndex:

Add condition on selected property & change selectedIndex value onSelectChanged.

Output:

Full code:

Conclusion:

This is how we create Data Tables in Flutter.

Thanks for reading this article.

If I got something wrong, let me know in the comments. I would love to improve.

You can also read: https://mobikul.com/get-storage-in-flutter/

Reference link: https://api.flutter.dev/flutter/material/DataTable-class.html

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home