Flutter UI Basics: Padding, Margin, and Alignment
Flutter UI Basics: Padding, Margin, and Alignment
Designing beautiful UIs in Flutter starts with understanding spacing and positioning. Three important layout concepts in Flutter are:
✅ 1. Padding
-
Padding is the space inside a widget — between the widget’s content and its boundary.
-
Use the
Paddingwidget to add padding.
π§ͺ Example:
π Variations:
✅ 2. Margin
-
Flutter doesn't have a direct
Marginwidget. -
Instead, use the
Containerwidget'smarginproperty. -
Margin is the space outside a widget — between the widget and others.
π§ͺ Example:
✅ 3. Alignment
-
Alignment positions the child within its parent.
-
Use
Alignor alignment properties in layout widgets likeContainer,Column, orRow.
π§ͺ Example using Align:
Example using Container:
π§ Summary Table
| Concept | Widget Used | Affects Position Of | Common Property |
|---|---|---|---|
| Padding | Padding / Container | Inside the widget | padding |
| Margin | Container | Outside the widget | margin |
| Alignment | Align / Container | Child within parent | alignment |
π― Final Tips
-
Combine these with
Row,Column,Center, andExpandedfor better layout control. -
Use Flutter DevTools to visualize padding and alignment live.
-
Consistent spacing = clean, professional UI.
Comments
Post a Comment