Reputation: 15664
I need to align "Scan check" in the center of Text widget. I try widget Align
but it not help.
snippet:
Widget _createScanCheckContainer() {
return new Container(
margin: const EdgeInsets.only(top: Constants.DEFAULT_MARGIN),
height: 56.0,
color: Color(Constants.COLOR_PRIMARY),
child: Row(children: [
new Align(
alignment: Alignment.center,
child: Text(
"Scan check",
style: TextStyle(
fontSize: 19.0, color: Colors.white),
))
]));
}
Here result.
Why Scan check is not on the center?
Upvotes: 0
Views: 62
Reputation: 6000
You don't need Align here, because its size is determined in accordance with its child.
Therefore it does not expand to Row's width.
You should use mainAxisAlignment property for Row to align your Text
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Scan check",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 19.0, color: Colors.white),
)
]
)
Upvotes: 1
Reputation: 451
Make the row center align all its children horizontally.
Widget _createScanCheckContainer() {
return new Container(
margin: const EdgeInsets.only(top: Constants.DEFAULT_MARGIN),
height: 56.0,
color: Color(Constants.COLOR_PRIMARY),
child: Row(children: [
new Align(
alignment: Alignment.center,
child: Text(
"Scan check",
style: TextStyle(
fontSize: 19.0, color: Colors.white),
))
], mainAxisAlignment: MainAxisAlignment.center));
}
Upvotes: 1