Set the space between Elements in Row Flutter
Solution 1:
There are many ways of doing it, I'm listing a few here:
-
Use
SizedBox
if you want to set some specific spaceRow( children: <Widget>[ Text("1"), SizedBox(width: 50), // give it width Text("2"), ], )
-
Use
Spacer
if you want both to be as far apart as possible.Row( children: <Widget>[ Text("1"), Spacer(), // use Spacer Text("2"), ], )
-
Use
mainAxisAlignment
according to your needs:Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, // use whichever suits your need children: <Widget>[ Text("1"), Text("2"), ], )
-
Use
Wrap
instead ofRow
and give somespacing
Wrap( spacing: 100, // set spacing here children: <Widget>[ Text("1"), Text("2"), ], )
-
Use
Wrap
instead ofRow
and give it alignmentWrap( alignment: WrapAlignment.spaceAround, // set your alignment children: <Widget>[ Text("1"), Text("2"), ], )
Solution 2:
MainAxisAlignment
start - Place the children as close to the start of the main axis as possible.
end - Place the children as close to the end of the main axis as possible.
center - Place the children as close to the middle of the main axis as possible.
spaceBetween - Place the free space evenly between the children.
spaceAround - Place the free space evenly between the children as well as half of that space before and after the first and last child.
spaceEvenly - Place the free space evenly between the children as well as before and after the first and last child.
Example:
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Row1'),
Text('Row2')
],
)
Solution 3:
Removing Space-:
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: new Text('Don\'t have an account?',
style: new TextStyle(color: Color(0xFF2E3233))),
onTap: () {},
),
GestureDetector(
onTap: (){},
child: new Text(
'Register.',
style: new TextStyle(
color: Color(0xFF84A2AF), fontWeight: FontWeight.bold),
))
],
),
OR
GestureDetector(
onTap: (){},
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text('Don\'t have an account?',
style: new TextStyle(color: Color(0xFF2E3233))),
new Text(
'Register.',
style: new TextStyle(
color: Color(0xFF84A2AF), fontWeight: FontWeight.bold),
)
],
),
),