24

I have no idea how to set table column size in Flutter. If I use Row, Expanded can be used, but TableRow does not allow it.

Please tell me some advice how to set table column size. The best solution for me is adjust to size of text length in columns.

Christian
  • 25,249
  • 40
  • 134
  • 225
tajihiro
  • 2,293
  • 7
  • 39
  • 60

3 Answers3

72

Method 1

You can use defaultColumnWidth inside Table if you want to set same width to each column,

Table(
    defaultColumnWidth: FixedColumnWidth(200.0),
...

Output

enter image description here


Method 2

you can use a different width for each column.

Table(
columnWidths: {
                0: FlexColumnWidth(1),
                1: FlexColumnWidth(4),
                2: FlexColumnWidth(4),
              },     
...

Output

enter image description here

Ravinder Kumar
  • 7,407
  • 3
  • 28
  • 54
23

For your specific case you can use

Table(
  defaultColumnWidth: IntrinsicColumnWidth(),
  ...
);

, since you want the column width to adjust to the text lengths. IntrinsicColumnWidth sizes the column based on the width of the content in each cell, ie, the column width increases or shrinks depending upon the length of the content in the cell.

Philippe Fanaro
  • 6,148
  • 6
  • 38
  • 76
Nuqo
  • 3,793
  • 1
  • 25
  • 37
16

You can also make two column widths fixed.

Table(
      border: TableBorder.all(color: Colors.black),
      columnWidths: {
            0: FixedColumnWidth(100.0),// fixed to 100 width
            1: FlexColumnWidth(),
            2: FixedColumnWidth(100.0),//fixed to 100 width
          },