Dynamic Row Height for DataTable in Flutter
Asked Answered
L

2

6

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.

Lavenialaver answered 30/9, 2021 at 17:0 Comment(1)
Please provide enough code so others can better understand or reproduce the problem.Cauterant
H
15

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",
        ),
      ),
    ),
  ],
)
Hassanhassell answered 28/7, 2023 at 11:52 Comment(0)
W
0

you didn't share any code. but you can use expanded inside rows and columns.

Row(children:[Expanded(child: yourWidget),])
Weismann answered 30/9, 2021 at 17:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.