4

I have a column with buttons where I want padding for, however the top most widget is a row that I do not want padding for.

Is it possible to exclude the row from the padding or do I have to define the padding for each and every button individually?

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440

3 Answers3

1

Is your row inside your column? If yes simply take your row out of the column so it will not get the padding.

Rodrigo Bastos
  • 2,230
  • 17
  • 17
1

You can create a seperate class that creates the buttons and specify the padding once. Then you can call that class again and again to create as many buttons as you want in the Column.

 

    class MakeButton extends StatelessWidget{
      final String _buttonCaption;

      MakeButton(this._buttonCaption);

      @override 
      Widget build (BuildContext context){
        return Padding(
          padding: EdgeInsets.all(10),
          child: FlatButton(
              onPressed: () {},
              child: Text(
              _buttonCaption
              ),
            ),
        );
      }
    }

 

Now you don't need to specify the padding for the Column and the Row will not have any padding.

 

    class Test extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text("Row DATA 1"),
                Text("Row DATA 2"),
                Text("Row DATA 3"),
              ],
            ),
            MakeButton("Flat Button 1"),
            MakeButton("Flat Button 2"),
            MakeButton("Flat Button 3"),
          ],
        );
      }
    }
 

It should look something like this - Image

Piyush Passi
  • 414
  • 1
  • 5
  • 7
1

Try this approach.

Column(
  children: <Widget>[
    Row(), // Row without padding
    Padding( // add Padding widget, make Column its child and put Buttons inside
      padding: your_padding_here, 
      child: Column(
        children: <Widget>[
          Button1(), 
          Button2(), 
        ],
      ),
    )
  ],
)
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440