Code:
new Container( alignment: FractionalOffset.center, child: new Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ new FlatButton( child: new Text('Don\'t have an account?', style: new TextStyle(color: Color(0xFF2E3233))), ), new FlatButton( child: new Text('Register.', style: new TextStyle(color: Color(0xFF84A2AF), fontWeight: FontWeight.bold),), onPressed: moveToRegister, ) ], ), ),
And here is the result: https://dartpad.dev/?id=6bbfc6139bdf32aa7b47eebcdf9623ba
How to fix that the two FlatButton
elements are side by side without space between the center of the screen width?
The Spacer widget in Flutter, allows you to add an empty space that you can adjust to match your design. By default, it takes all the available space and shifts the adjacent widget to the far side. Using the flex property of the Spacer widget, you can control the space between widgets.
It is not compulsory to provide a child widget to SizedBox. For instance, if you are having two Card widgets and you want to give space between them, then you can use SizedBox. You can add SizedBox between those cards and pass the required height and width values.
You can use Padding widget in between those two widget or wrap those widgets with Padding widget. SizedBox widget can be use in between two widget to add space between two widget and it makes code more readable than padding widget.
There are many ways of doing it, I'm listing a few here:
Use SizedBox
if you want to set some specific space
Row( 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 of Row
and give some spacing
Wrap( spacing: 100, // set spacing here children: <Widget>[ Text("1"), Text("2"), ], )
Use Wrap
instead of Row
and give it alignment
Wrap( alignment: WrapAlignment.spaceAround, // set your alignment children: <Widget>[ Text("1"), Text("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') ], )
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