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.
You can use defaultColumnWidth inside Table if you want to set same width to each column, Table( defaultColumnWidth: FixedColumnWidth(200.0), ... you can use a different width for each column. Table( columnWidths: { 0: FlexColumnWidth(1), 1: FlexColumnWidth(4), 2: FlexColumnWidth(4), }, ...
Show activity on this post. Create the list beforehand in the build method. final rows = <TableRow>[]; for (var rowData in myRowDataList) { rows. add(TableRow( ... // Generate a TableRow using rowData )); } ... Table( columnWidths: { 0: FlexColumnWidth(1.0), 1: FlexColumnWidth(2.0), }, border: TableBorder.
What I found working in this case (when you want to add padding between rows in a table) is to wrap Text Widget with Container and add padding property to one of your elements (that is potentially the 'tallest' one) and use alignment property for other containers where you need to align text within the row.
Method 1
You can use defaultColumnWidth
inside Table
if you want to set same width to each column,
Table(
defaultColumnWidth: FixedColumnWidth(200.0),
...
Output
Method 2
you can use a different width for each column.
Table(
columnWidths: {
0: FlexColumnWidth(1),
1: FlexColumnWidth(4),
2: FlexColumnWidth(4),
},
...
Output
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.
You can also make two column width 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
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With