I just want to do the most simplest of things: I just want to have a button with the text aligned to the right. For some reason I can't figure this out.
I tried textAlign: TextAlign.right but it's still in the centre. I tried making a row inside the button with mainAxisAlignment.end but nope, still in center. for some reason it works if I use main axis alignment.end on a column instead of a row (puts it at bottom instead of right)
This is what I have so far:
FlatButton(
color: Colors.black,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text(
"M",
textAlign: TextAlign.right,
style: TextStyle(
color: mColor, fontSize: 10.0),
),
],
),
Flutter – Center Align Text in Text Widget To center align the text in a Text widget, provide textAlign property with value TextAlign. center .
to set center text vertically and horizontally in Flutter Just Use Center() widget. It will set Text to horizontally and vertically Center. The text widget has textAlign property you can give them start, end, center, justify, left, right. We can use Align Widget to set text in center align has alignment property.
You should put your 'Text' in 'Align' to align your text left, right, top, bottom etc. As-
FlatButton(
color: Colors.blue,
textColor: Colors.white,
padding: EdgeInsets.all(8.0),
splashColor: Colors.blueAccent,
onPressed: () {
/*...*/
},
child: Align(
alignment: Alignment.center,
child: Text(
"Flat",
style: TextStyle(fontSize: 20.0),
textAlign: TextAlign.center
),
))
Put it in an inkwell
InkWell(
onTap: doSomething,
child: SizedBox(
height: 100,
width: 100,
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black)),
child: Text(
'hello',
textAlign: TextAlign.right,
),
),
),
),
It works for me
ButtonTheme(
child: FlatButton(
padding: EdgeInsets.all(0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Button text",
style: TextStyle(
color: ThemeColors.primaryDark,
fontWeight: FontWeight.normal,
fontSize: ThemeSizes.normalFont,
),
textAlign: TextAlign.left,
),
),
onPressed: () => _doSomething(),
),
)
For the new Buttons and Button Themes:
TextButton(
onPressed: () {},
child: Text('Cancel'),
style: ButtonStyle(
alignment: Alignment.centerLeft, // <-- had to set alignment
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
EdgeInsets.zero, // <-- had to set padding to zero
),
),
),
I found that using the padding values in the FlatButton widget worked very well.
See example below...
FlatButton(
onPressed: () {
/*...*/
},
padding: EdgeInsets.only(right: 10.0, bottom: 1.0, top: 1.0),
child: Text(
'Getting Started',
style: TextStyle(
color: Colors.blueGrey[900],
fontSize: 12.0
), //TextStyle
), //Text
), //FlatButton
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