Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set column width in flutter

I need to set a Column width in flutter, I have to do a layout with 3 sections, one should be 20% of the screen, the other one 60% and the last one 20%. I know that those 3 columns should be into a row, but I don't know a way to set the size, when I do that, the 3 columns take the same size.

I will appreciate any feedback.

like image 724
Joseph Arriaza Avatar asked Oct 12 '18 17:10

Joseph Arriaza


People also ask

How do you adjust column width in a table Flutter?

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), }, ...

How do you change the width of a row in Flutter?

Change width of a row Row normally takes available space and we can control that by wrapping inside a Container or SizedBox widget. You can wrap the Row inside the Container and add width to the container. Then the Row will take the same width as a Container.


2 Answers

Instead of hard-coding the size, I would suggest using Flex like

Row(       children: <Widget>[         Expanded(           flex: 2, // 20%           child: Container(color: Colors.red),         ),         Expanded(           flex: 6, // 60%           child: Container(color: Colors.green),         ),         Expanded(           flex: 2, // 20%           child: Container(color: Colors.blue),         )       ],     ) 

Which will produce like below,

enter image description here

like image 171
Dinesh Balasubramanian Avatar answered Sep 21 '22 09:09

Dinesh Balasubramanian


Limiting the width of a Column could be

  1. Limiting the width of Column itself, use SizedBox

    SizedBox(   width: 100, // set this   child: Column(...), ) 

2 (A). Limiting width of children inside Column, without hardcoding values

Row(   children: <Widget>[     Expanded(       flex: 3, // takes 30% of available width        child: Child1(),     ),     Expanded(       flex: 7, // takes 70% of available width         child: Child2(),     ),   ], ) 

2 (B). Limiting width of children inside Column, with hardcoding values.

Row(   children: <Widget>[     SizedBox(       width: 100, // hard coding child width       child: Child1(),     ),     SizedBox(       width: 200, // hard coding child width       child: Child2(),     ),   ], ) 
like image 38
CopsOnRoad Avatar answered Sep 21 '22 09:09

CopsOnRoad