π§© UI & Layout in Flutter
π§© UI & Layout in Flutter
A Beginner’s Guide to Building Beautiful Interfaces
✅ What is UI & Layout in Flutter?
In Flutter, UI (User Interface) is built using widgets. Everything you see on the screen is a widget — from buttons and text to layouts and animations.
Layout means arranging these widgets on the screen — deciding their size, position, and alignment.
πΉ Basic Building Blocks: Widgets
StatelessWidget: UI doesn’t change over time (static).
StatefulWidget: UI can change dynamically (interactive).
π² Common Layout Widgets
Flutter provides several widgets to organize and layout your UI:
Widget Purpose Example Usage
Container A box to hold and style widgets Padding, margin, background color
Row Arrange children horizontally Place buttons side by side
Column Arrange children vertically Stack text fields vertically
Stack Overlap widgets on top of each other Overlay text on image
Expanded Fill available space in Row/Column Make buttons stretch equally
Padding Add space around widgets Separate elements
Center Center a widget within its parent Center a logo
SizedBox Create empty space or fixed-size widget Add gaps between widgets
π Example: Simple Layout with Column and Row
dart
Copy
Edit
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Flutter Layout Example')),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Hello Flutter!', style: TextStyle(fontSize: 24)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Icon(Icons.star, color: Colors.blue, size: 50),
Icon(Icons.favorite, color: Colors.red, size: 50),
Icon(Icons.thumb_up, color: Colors.green, size: 50),
],
),
],
),
),
);
}
}
π§© Layout Tips
Use mainAxisAlignment and crossAxisAlignment to control alignment inside Row and Column.
Use Flexible and Expanded to manage how widgets take up space.
Nest layout widgets for complex UIs.
Use MediaQuery to make your UI responsive across screen sizes.
π¨ Styling Widgets
Use Container with properties like padding, margin, decoration (colors, borders, shadows).
Use TextStyle to customize font size, color, weight, etc.
Wrap widgets with GestureDetector for tap/click interactions.
π Useful Flutter Layout Widgets at a Glance
Widget Use Case
Scaffold Basic app structure (AppBar, Body)
ListView Scrollable lists
GridView Grid layout
SafeArea Avoid notches and system UI overlaps
Align Align child within parent
FractionallySizedBox Size widgets relative to parent
✅ Summary
Flutter makes UI building easy and flexible through composition of widgets. Understanding basic layout widgets like Row, Column, and Container is key to building beautiful apps.
Learn Flutter Training in Hyderabad
Read More
Working with Text and Images in Flutter
How to Use the Flutter Debug Console
Hot Reload vs Hot Restart in Flutter
Dart Basics for Flutter Developers
Visit Our IHUB Talent Training Institute in Hyderabad
Comments
Post a Comment