Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you discard padding in a FlatButton in Flutter?

Tags:

flutter

dart

I have two FlatButtons in a row. The row is a column which is in turn in a container that is used for the padding of the screen. This container has padding of right:20 and left:20. I want my buttons to be 20 in from left and 20 in from the right to keep everything aligned in my column. I know the FlatButton widget has default padding and I've tried the solutions in this question Changing the buttons to GestureDectectors widgets works with alignment but doesn't have a very nice user experience, the area to click is too small maybe. Ideally I'd like to remove the padding of the FlatButton on one side left/right depending on which button. Here is my code

Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
    FlatButton(
    child: new Text('SIGN IN',
        style: Theme.of(context).textTheme.body1),
    onPressed: () {
        Navigator.push(
            context, SignInPage(widget.onSignedIn));
    },

    ),
    new FlatButton(
    child: new Text(
        'SIGN UP',
        style: Theme.of(context).textTheme.body1,
    ),
    onPressed: () {
        Navigator.push(
            context, SignUpPage(widget.onSignedIn));
    },
    ),
]),
like image 291
flutter Avatar asked Sep 10 '26 18:09

flutter


2 Answers

Now with the deprecation of the FlatButton for TextButton

TextButton(
    style: TextButton.styleFrom(padding: EdgeInsets.all(0)),
    ...
)
like image 173
Aaron Halvorsen Avatar answered Sep 13 '26 09:09

Aaron Halvorsen


Use zero padding, for example

padding: EdgeInsets.zero,
like image 31
68060 Avatar answered Sep 13 '26 10:09

68060



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!