Android – Flutter padding for all widgets

androidflutterios

I'm trying to add some padding to the top and bottom of some text and icons in a Card widget. I found that flutter has an easy way to do this for containers, but can't seem to find a way to do this with other widgets (except for wrapping them in a container). This is the code I've got so far:

  body: new Container(
    padding: new EdgeInsets.all(10.0),
    child: new Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget> [
        new Card(
          color: Colors.white70,
          child: new Container(
            padding: new EdgeInsets.all(10.0),
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget> [ //Padding between these please
                new Text("I love Flutter", style: new TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold)),
                new Icon(Icons.favorite, color: Colors.redAccent, size: 50.0)
              ]
            )
          )
        )
      ]
    )
  )

So in my children of column, I'd like to add some padding to the top and bottom without having to insert a new Container. Is this possible?

Best Answer

You can use Padding, which is a very simple Widget that just takes another Widget as a child and an EdgeInsets object like the one you are already using as padding.

This approach of "composition over inheritance" in Flutter is very intentional. You can find a recent discussion of the pros and cons on Flutter's Gitter channel.

Related Topic