Set dynamic height value to dataRowHeight Property of DataTable Widget to fit different Row's content - #flutter
Asked Answered
L

1

8

I need to set dynamic height value to dataRowHeight property of DataTable Widget to fit different Row's contents and I don't want to use Table Widget which allows that. - #flutter

As by default, it uses kMinInteractiveDimension value of (48.0) as defined in DataTableThemeData.

DataTable(dataRowHeight: 150, columns: [DataColumn()...], rows: [DataRow()....])

Check this image:

Lalo answered 15/10, 2020 at 12:11 Comment(0)
M
1

If you want to let the row vary in a predictable way only changing based on the actual height of the contents of the row, you can do this by NOT setting dataRowHeight, which is deprecated anyway, but instead setting dataRowMinHeight and dataRowMaxHeight to different values. If you set those differently, then each row's height will be driven by its own contents within the bounds of the defined min and max.

If you are looking instead to define a variable row height based on some independent thing (like every odd row tall and every even row short or whatever), that is not possible with DataTable.

DataTable calculates an effectiveDataRowMinHeight and effectiveDataRowMaxHeight from either a given dataRowHeight, given dataRowMinHeight and dataRowMaxHeight, or values from the Theme or some other automatic constants. Then, DataTable uses that effective min and max for every cell in the table. Inside DataTable's build() method, at one point, it runs its own _buildDataCell() method on each cell in each row. In that method, it applies the same min and max to each cell.

Then, when each table's row is laid out, it will set the same height for all cells in that row based on the min and max they all have and the desired height for each.

*edited to clarify that the min and max heights need to be set to different values for this to work as intended.

Mounting answered 22/5 at 14:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.