Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Row Height for DataTable in Flutter

I'm new to flutter.

I have a Datatable with data, but not all data is the same length, some are bigger than others. So my question is, can the height of the rows be made dynamic to fit the length of the data?

I know that there is a dataRowHeight property, but if I adjust it to show the longest data, the small ones have a very noticeable white space and it does not work for me.

like image 426
iRedD Avatar asked Jul 14 '26 01:07

iRedD


1 Answers

Here is simple solution.

Give infinity height to dataRowMaxHeight

dataRowMaxHeight: double.infinity, // For dynamic row content height.

Example

DataTable(
  dataRowMaxHeight: double.infinity,
  columns: const [
    // Your column data
    DataColumn(label: Text("Column Heading")),
  ],
  rows: [
    DataCell(
      SizedBox(
      width: 100, // <- Give Here width of column as per your need.
      child: Text(
         "Long text here",
        ),
      ),
    ),
  ],
)
like image 88
Sharath B Naik Avatar answered Jul 17 '26 19:07

Sharath B Naik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!