Search code snippets, questions, articles...

Add margin to container in Flutter

Container(
    margin: EdgeInsets.all(40.0),
    child: Text(
        'Hello world'
    ),
),

If you want to add margin or some space around a Container widget in Flutter, you can use margin property for that and apply value to it by using 'EdgeInserts'. In the above code snippet, we have added a '40.0' margin around the Container. 'EdgeInserts.all' is used to add margin around all-sided uniformly.

Was this helpful?
1 Comments

To add different margins from specific sides use below code

Container(
    margin: EdgeInsets.only(top: 100.0, left: 50.0, right: 30.0, bottom: 20.0),
    child: Text(
        'Hello world'
    ),
),

To add padding horizontally or vertically in symmetric, use

Container(
    margin: EdgeInsets.symmetric(horizontal: 100.0, vertical: 50.0),
    child: Text(
        'Hello world'
    ),
),