I have a Column
widget with two TextField
widgets as children and I want to have some space between both of them.
I already tried mainAxi
There are many answers here but I will put here the most important one which everyone should use.
1. Column
Column(
children: <Widget>[
Text('Widget A'), //Can be any widget
SizedBox(height: 20,), //height is space betweeen your top and bottom widget
Text('Widget B'), //Can be any widget
],
),
2. Wrap
Wrap(
direction: Axis.vertical, // We have to declare Axis.vertical, otherwise by default widget are drawn in horizontal order
spacing: 20, // Add spacing one time which is same for all other widgets in the children list
children: <Widget>[
Text('Widget A'), // Can be any widget
Text('Widget B'), // Can be any widget
]
)
You may have to use SizedBox() widget between your column's children. Hope that'll be usefull
There are many ways of doing it, I'm listing a few here.
Use Container
and give some height:
Column(
children: <Widget>[
Widget1(),
Container(height: 10), // set height
Widget2(),
],
)
Use Spacer
Column(
children: <Widget>[
Widget1(),
Spacer(), // use Spacer
Widget2(),
],
)
Use Expanded
Column(
children: <Widget>[
Widget1(),
Expanded(child: SizedBox()), // use Expanded
Widget2(),
],
)
Use mainAxisAlignment
Column(
mainAxisAlignment: MainAxisAlignment.spaceAround, // mainAxisAlignment
children: <Widget>[
Widget1(),
Widget2(),
],
)
Use Wrap
Wrap(
direction: Axis.vertical, // make sure to set this
spacing: 20, // set your spacing
children: <Widget>[
Widget1(),
Widget2(),
],
)
The sized box will not help in the case, the phone is in landscape mode.
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Container(
margin: EdgeInsets.all(15.0),
decoration: BoxDecoration(
color: Color(0xFF1D1E33),
borderRadius: BorderRadius.circular(10.0),
),
),
),
Expanded(
child: Container(
margin: EdgeInsets.all(15.0),
decoration: BoxDecoration(
color: Color(0xFF1D1E33),
borderRadius: BorderRadius.circular(10.0),
),
),
),
Expanded(
child: Container(
margin: EdgeInsets.all(15.0),
decoration: BoxDecoration(
color: Color(0xFF1D1E33),
borderRadius: BorderRadius.circular(10.0),
),
),
),
],
)
The same way SizedBox is used above for the purpose of code readability, you can use the Padding widget in the same manner and not have to make it a parent widget to any of the Column's children
Column(
children: <Widget>[
FirstWidget(),
Padding(padding: EdgeInsets.only(top: 40.0)),
SecondWidget(),
]
)
Columns Has no height by default, You can Wrap your Column to the Container and add the specific height to your Container. Then You can use something like below:
Container(
width: double.infinity,//Your desire Width
height: height,//Your desire Height
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('One'),
Text('Two')
],
),
),