Hi everyone! ![]()
When building custom widgets in FlutterFlow, aligning your content properly is crucial for maintaining a clean, responsive, and visually appealing UI across all devices.
This post will walk you through:
Ways to align content
Best practices
Useful code snippets
1. Using Alignment in Container
To align the inner content of a Container, use the alignment property:
dart
CopyEdit
Container(
alignment: Alignment.center, // Aligns child in the center
child: Text('Centered Text'),
)
Best for: Simple widgets where you want to align a single child.
2. Using Center or Align Widget
If you want more control or youβre nesting multiple widgets, use Center or Align:
dart
CopyEdit
Center(
child: Text('Centered Text'),
)
Align(
alignment: Alignment.bottomRight,
child: Icon(Icons.arrow_forward),
)
Center is shorthand for Align(alignment: Alignment.center)
3. Using Row, Column, or Stack for Layout
Use layout widgets to organize multiple items with flexible alignment:
dart
CopyEdit
Row(
mainAxisAlignment: MainAxisAlignment.center, // Horizontally center
crossAxisAlignment: CrossAxisAlignment.center, // Vertically center
children: [
Icon(Icons.star),
SizedBox(width: 8),
Text('Starred'),
],
)
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person),
Text('Profile'),
],
)
4. Padding & SizedBox for Spacing
Always use consistent spacing:
dart
CopyEdit
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Padded Text'),
)
SizedBox(height: 10), // Vertical space
Best Practices
1. Use alignment inside Container for single-child widgets
2. Use Row and Column for multiple widgets
3. Use MainAxisAlignment and CrossAxisAlignment smartly
4. Combine Padding and SizedBox to avoid crammed UI
5. Test on mobile and web for responsiveness
6. Wrap widgets with Expanded or Flexible in rows/columns to handle overflow
Real Example (Custom Avatar Badge)
dart
CopyEdit
Container(
padding: EdgeInsets.all(6),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
border: Border.all(color: Colors.grey),
),
child: Center(
child: Text(
'M',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
)
Conclusion
Aligning content in FlutterFlow custom widgets is easy once you understand alignment, Center, Row/Column, and spacing tools like Padding and SizedBox.
Mastering layout alignment = Better UI + Better UX! ![]()
Let me know if youβve found other tricks for alignment, or if youβre stuck on a specific widget layout - happy to help!