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 Padding widget to add padding.

πŸ§ͺ Example:

Padding( padding: EdgeInsets.all(16.0), // uniform padding on all sides child: Text("Hello, Flutter!"), )

πŸ” Variations:

EdgeInsets.only(left: 10, right: 20) EdgeInsets.symmetric(vertical: 10, horizontal: 20)

✅ 2. Margin

  • Flutter doesn't have a direct Margin widget.

  • Instead, use the Container widget's margin property.

  • Margin is the space outside a widget — between the widget and others.

πŸ§ͺ Example:

Container( margin: EdgeInsets.all(12.0), child: Text("This has margin"), )

✅ 3. Alignment

  • Alignment positions the child within its parent.

  • Use Align or alignment properties in layout widgets like Container, Column, or Row.

πŸ§ͺ Example using Align:

Align( alignment: Alignment.centerRight, child: Text("Aligned Right"), )

Example using Container:

Container( alignment: Alignment.topLeft, child: Text("Top Left"), )

🧠 Summary Table

ConceptWidget UsedAffects Position OfCommon Property
PaddingPadding / ContainerInside the widgetpadding
MarginContainerOutside the widgetmargin
AlignmentAlign / ContainerChild within parentalignment


🎯 Final Tips

  • Combine these with Row, Column, Center, and Expanded for better layout control.

  • Use Flutter DevTools to visualize padding and alignment live.

  • Consistent spacing = clean, professional UI.


Comments

Popular posts from this blog

Tosca System Requirements and Installation Guide (Step-by-Step)

How to Install Selenium for Python Step-by-Step

Tosca Commander: A Beginner’s Overview