Search code examples
buttontextdartflutteralignment

How to align text in a button in flutter?


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),
        ),
    ],
),

Solution

  • 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,
                ),
            ),
        ),
    ),