Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning weights to Columns and Rows in Flutter

I want to give equal spacing to all rows in Flutter App. is there anything like weights or any such widget which can be used. For example, I have 2 Row elements in my app. I want both elements to take equal/half width of the screen.

like image 773
Developine Avatar asked Jun 22 '18 06:06

Developine


2 Answers

Inside a Flex (i.e. Row or Column), Expanded consumes the remaining available space. If you put two Expandeds in the same Flex they share the remaining available space equally (by default).

You assign 'weights' to Expandeds with their flex parameter, which would allow you to, say, have them share the remaining space 60/40, instead of 50/50, etc.

like image 172
Richard Heap Avatar answered Nov 15 '22 07:11

Richard Heap


Flexible is your friend

Example with the Row:

Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
      Flexible(
        flex: 5,
        child: SomeFirstWidget(),
      ),
      Flexible(
        flex: 2,
        child: SomeSecondWidget(),
    ],
)

The flex param is the weight.

like image 33
Andrew Avatar answered Nov 15 '22 07:11

Andrew