How to Add Padding and Margins in Flutter Widget

Padding and margins are important aspects of creating good UI/UX designs in your Flutter apps. 


In this article, we will learn how to add padding and margins to your Flutter widgets using the EdgeInsets class and the Container widget.


Code Sample:

Padding(
  padding: EdgeInsets.all(16.0),
  child: Text('Hello World!'),
)

Properties:
padding: EdgeInsets - This property specifies the amount of padding to be added to the widget. You can add padding to all four sides or individual sides as per your requirement.
margin: EdgeInsets - This property specifies the amount of margin to be added to the widget. You can add margin to all four sides or individual sides as per your requirement.
..
Using the Container widget, you can also add padding and margins to a widget. 
Here is an example:


Container(
  margin: EdgeInsets.all(16.0),
  padding: EdgeInsets.all(8.0),
  child: Text('Hello World!'),
)
..
In this example, we have used the margin property to add margin to the container and the padding property to add padding to the child widget. You can use the EdgeInsets class to specify the amount of padding and margin you want to add.

Adding padding and margins to your widgets can help you create better UI/UX designs and make your app look more professional.

Comments