Flutter Layouts: Row, Column, Stack
Flutter is known for its powerful and flexible UI system, which allows developers to build beautiful user interfaces with ease. Among the most commonly used layout widgets in Flutter are Row, Column, and Stack. Understanding how these work is essential for any Flutter developer.
Row Widget
The Row widget arranges its children horizontally in a single line. It’s ideal when you want to place items side by side.
Key Properties:
mainAxisAlignment: Controls horizontal alignment (start, end, center, spaceBetween, etc.).
crossAxisAlignment: Aligns children vertically.
Example:
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(Icons.home),
Icon(Icons.star),
Icon(Icons.settings),
],
)
This code creates a horizontal row of icons spaced evenly across the screen.
2. Column Widget
The Column widget arranges its children vertically. It’s perfect for building screens that need vertical stacking like forms or list items.
Key Properties:
mainAxisAlignment: Controls vertical spacing.
crossAxisAlignment: Aligns children horizontally.
Example:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Name'),
TextField(),
SizedBox(height: 20),
Text('Email'),
TextField(),
],
)
This creates a simple form with labels and input fields stacked vertically.
3. Stack Widget
The Stack widget overlays widgets on top of each other. It’s useful for creating complex UIs like banners with text on top of images, floating buttons, or layered designs.
Key Properties:
alignment: Aligns children within the stack.
fit: Controls how the children are sized.
Example:
Stack(
children: [
Image.asset('assets/background.jpg'),
Positioned(
bottom: 20,
left: 20,
child: Text(
'Welcome!',
style: TextStyle(color: Colors.white, fontSize: 24),
),
),
],
)
This displays an image with text positioned at the bottom left corner.
Conclusion
Row, Column, and Stack are fundamental layout widgets in Flutter that offer great flexibility and control over UI design. Mastering these widgets allows you to build everything from simple screens to complex, multi-layered interfaces. As you gain confidence, combining them effectively will unlock the full potential of Flutter’s UI system.
Learn Flutter Training Course
Read More:
Dart Programming Basics for Flutter Developers
Creating Beautiful UI with Flutter
Handling User Input in Flutter
Visit Quality Thought Training Institute
Comments
Post a Comment