StatelessWidget, Text, Container, Scaffold, Icon, Image and Theme · 4 h
Place widgets exactly where you want them · 4 h
The ready-made parts every app is built from · 4 h
Show 10 or 10,000 items with the same code · 4 h
Course cards, price tags, notice boards: a styled box with text inside.
Top bar, body, floating button and drawer all come ready from Scaffold.
A ProductCard widget written once is used on 20 screens. Less code, fewer bugs.
A StatelessWidget is a widget that never changes by itself: you give it data, it draws it. You write a class with a build() method that returns other widgets.
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text('This is my own widget!'),
),
),
);
}
}void main() {
runApp(const MaterialApp(
home: Scaffold(
body: Padding(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Big and bold',
style: TextStyle(fontSize: 30,
fontWeight: FontWeight.bold)),
Text('Coloured italic',
style: TextStyle(color: Colors.teal,
fontStyle: FontStyle.italic, fontSize: 22)),
Text('Spaced letters',
style: TextStyle(letterSpacing: 4, fontSize: 20)),
Text('Underlined',
style: TextStyle(
decoration: TextDecoration.underline,
fontSize: 22)),
],
),
),
),
));
}width, height, padding (inside), margin (outside).
color or decoration: BoxDecoration(...) for gradient, border, radius, shadow.
BoxShape.circle makes a round box; borderRadius rounds the corners.
alignment: Alignment.center puts the child in a chosen spot.
color OR decoration, not both. Put the colour inside BoxDecoration when you use it.Top bar with title and action icons.
The main content of the page.
The round main-action button.
Side menu and bottom tabs (Module 11).
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.favorite, color: Colors.red, size: 48),
const SizedBox(height: 12),
const CircleAvatar(
radius: 36,
backgroundColor: Colors.indigo,
child: Text('AK', style: TextStyle(fontSize: 24, color: Colors.white)),
),
const SizedBox(height: 12),
ClipRRect(
borderRadius: BorderRadius.circular(16),
child: Image.network('https://example.com/ranchi.jpg',
width: 200, height: 110, fit: BoxFit.cover),
),
],
),
),
),
));
}Our own widget takes data in its constructor (title, hours) and draws it. Change the design once in CourseTile and every tile in the app changes.
class CourseTile extends StatelessWidget {
final String title;
final int hours;
const CourseTile({super.key, required this.title, required this.hours});
@override
Widget build(BuildContext context) {
return ListTile(
leading: const Icon(Icons.school),
title: Text(title),
subtitle: Text('$hours hours'),
);
}
}
// use it as many times as you like
Column(children: const [
CourseTile(title: 'Flutter', hours: 80),
CourseTile(title: 'Python', hours: 60),
])Instead of colouring every widget by hand, set a Theme once. Buttons, the AppBar, switches and sliders all pick up the colour. Theme.of(context) reads it anywhere.
MaterialApp(
theme: ThemeData(
colorSchemeSeed: Colors.teal, // one colour makes a full palette
useMaterial3: true,
),
home: const HomePage(),
)
// anywhere below, read the theme:
Text('Hello',
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
),
)const tells Flutter "this widget never changes".
Flutter builds it once and reuses it, so the app runs faster and uses less battery.
Put const in front of widgets whose values are fixed: const Text('Hi').
The editor underlines places where const can be added. Press Ctrl+. and accept.
$name), the widget is not constant. That is normal.void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Text('My first StatelessWidget',
style: TextStyle(fontSize: 24)),
),
),
);
}
}void main() {
runApp(const MaterialApp(
home: Scaffold(
body: Padding(
padding: EdgeInsets.all(20),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text('Ranchi Mart', style: TextStyle(fontSize: 34, fontWeight: FontWeight.bold)),
Text('Fresh groceries, fast', style: TextStyle(fontSize: 18, color: Colors.green, fontStyle: FontStyle.italic)),
SizedBox(height: 14),
Text('OFFER', style: TextStyle(letterSpacing: 6, fontSize: 20)),
Text('Old price', style: TextStyle(decoration: TextDecoration.lineThrough, color: Colors.grey)),
SizedBox(height: 14),
Text('This is a very long description of the product that will not fit in one line on a small phone screen.',
maxLines: 2, overflow: TextOverflow.ellipsis),
]),
),
),
));
}void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Container(
width: 240, height: 90, alignment: Alignment.center,
decoration: BoxDecoration(
gradient: const LinearGradient(colors: [Colors.orange, Colors.pink]),
borderRadius: BorderRadius.circular(16)),
child: const Text('50% OFF', style: TextStyle(color: Colors.white, fontSize: 28)),
),
const SizedBox(height: 16),
Container(
width: 90, height: 90,
decoration: const BoxDecoration(color: Colors.teal, shape: BoxShape.circle),
child: const Icon(Icons.shopping_bag, color: Colors.white, size: 44),
),
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 2), borderRadius: BorderRadius.circular(20)),
child: const Text('In stock'),
),
]),
),
),
));
}void main() {
runApp(MaterialApp(
home: Scaffold(
backgroundColor: Colors.grey.shade100,
appBar: AppBar(
title: const Text('Ranchi Mart'),
actions: [
IconButton(icon: const Icon(Icons.search), onPressed: () {}),
IconButton(icon: const Icon(Icons.shopping_cart), onPressed: () {}),
],
),
body: const Center(child: Text('Products will come here')),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.add),
),
),
));
}void main() {
runApp(const MaterialApp(
home: Scaffold(
body: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(16)),
child: Image.network('https://example.com/ranchi-falls.jpg', width: 260, height: 130, fit: BoxFit.cover),
),
SizedBox(height: 14),
CircleAvatar(radius: 34, backgroundColor: Colors.deepPurple,
child: Text('NK', style: TextStyle(fontSize: 22, color: Colors.white))),
SizedBox(height: 8),
Text('Nandan Kumar', style: TextStyle(fontSize: 22)),
Row(mainAxisSize: MainAxisSize.min, children: [Icon(Icons.location_on, color: Colors.red), Text('Ranchi')]),
]),
),
),
));
}void main() {
runApp(MaterialApp(
home: Scaffold(
backgroundColor: Colors.blue.shade50,
body: Center(
child: Container(
width: 320, padding: const EdgeInsets.all(16),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16),
boxShadow: const [BoxShadow(color: Colors.black12, blurRadius: 10)]),
child: Row(children: [
Container(
width: 64, height: 64,
decoration: BoxDecoration(color: Colors.blue.shade100, borderRadius: BorderRadius.circular(14)),
child: const Icon(Icons.phone_android, size: 36, color: Colors.blue),
),
const SizedBox(width: 14),
const Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text('Flutter App Development', style: TextStyle(fontSize: 17, fontWeight: FontWeight.bold)),
Text('80 hours - Ranchi'),
Text('Rs 14,999', style: TextStyle(color: Colors.green)),
]),
]),
),
),
),
));
}class CourseTile extends StatelessWidget {
final String title;
final int hours, fee;
final IconData icon;
const CourseTile({super.key, required this.title, required this.hours, required this.fee, required this.icon});
@override
Widget build(BuildContext context) {
return Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
child: ListTile(leading: Icon(icon, size: 34, color: Colors.indigo),
title: Text(title), subtitle: Text('$hours hours'), trailing: Text('Rs $fee')),
);
}
}
void main() {
runApp(const MaterialApp(
home: Scaffold(
body: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
CourseTile(title: 'Flutter', hours: 80, fee: 14999, icon: Icons.phone_android),
CourseTile(title: 'Python', hours: 60, fee: 9999, icon: Icons.code),
CourseTile(title: 'Excel', hours: 30, fee: 3999, icon: Icons.table_chart),
]),
),
));
}void main() {
runApp(MaterialApp(
theme: ThemeData(colorSchemeSeed: Colors.teal, useMaterial3: true),
home: const Home(),
));
}
class Home extends StatelessWidget {
const Home({super.key});
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
appBar: AppBar(title: const Text('Themed app'), backgroundColor: colors.primaryContainer),
body: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Text('Primary colour text', style: TextStyle(fontSize: 22, color: colors.primary)),
const SizedBox(height: 12),
ElevatedButton(onPressed: () {}, child: const Text('Themed button')),
const SizedBox(height: 12),
Icon(Icons.verified, size: 48, color: colors.primary),
]),
),
);
}
}class Notice {
final String title, date;
final IconData icon;
final Color color;
const Notice(this.title, this.date, this.icon, this.color);
}
class NoticeCard extends StatelessWidget {
final Notice n;
const NoticeCard(this.n, {super.key});
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.fromLTRB(14, 8, 14, 0), padding: const EdgeInsets.all(14),
decoration: BoxDecoration(color: n.color.withOpacity(0.12), borderRadius: BorderRadius.circular(14),
border: Border(left: BorderSide(color: n.color, width: 6))),
child: Row(children: [
Icon(n.icon, color: n.color, size: 32), const SizedBox(width: 12),
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(n.title, style: const TextStyle(fontSize: 17, fontWeight: FontWeight.bold)),
Text(n.date),
]),
]),
);
}
}
void main() {
const notices = [
Notice('Annual Day on 14 Dec', '10 Nov 2026', Icons.celebration, Colors.purple),
Notice('Fee last date 30 Nov', '08 Nov 2026', Icons.payments, Colors.red),
Notice('Chhath holiday', '05 Nov 2026', Icons.event_busy, Colors.orange),
Notice('PTM this Saturday', '02 Nov 2026', Icons.groups, Colors.teal),
];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('DAV Notice Board')),
body: Column(children: notices.map((n) => NoticeCard(n)).toList()),
)));
}field() builds each box. In Module 10 we make the boxes work.Widget field(String t) => Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(10)),
child: Text(t, style: const TextStyle(color: Colors.grey)),
);
void main() {
runApp(MaterialApp(
theme: ThemeData(colorSchemeSeed: Colors.indigo, useMaterial3: true),
home: Scaffold(
body: Padding(
padding: const EdgeInsets.all(28),
child: Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.stretch, children: [
const Icon(Icons.school, size: 80, color: Colors.indigo),
const Text('BrainBit Infotech Learner', textAlign: TextAlign.center, style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold)),
const Text('Sign in to continue', textAlign: TextAlign.center),
const SizedBox(height: 28),
field('Mobile number'),
const SizedBox(height: 12),
field('Password'),
const SizedBox(height: 20),
FilledButton(onPressed: () {}, child: const Text('LOGIN')),
TextButton(onPressed: () {}, child: const Text('New student? Register')),
]),
),
),
));
}A class with build() that draws fixed data.
Size, weight, colour, spacing, decoration, overflow.
margin, padding, decoration, size, child, alignment.
appBar, body, FAB, drawer: the frame of a screen.
Constructor data in, widgets out. Write once, reuse.
One seed colour styles the whole app; Theme.of(context) reads it.
A WhatsApp chat row is a Row (photo, a Column with name and message, time).
The search box takes all free space while the icons keep their size.
The red number badge on a cart icon, the "NEW" tag on a product photo.
Flutter layout has one rule: constraints go down, sizes go up, parent sets the position.
A parent tells its child: "you may be this wide and this tall at most".
The child chooses its size inside those limits and reports it back up.
The parent decides where the child sits (centre, top-left, after the other child).
Column goes top to bottom, Row goes left to right. Each has a main axis (its own direction) and a cross axis (the other direction).
start, center, end, spaceBetween, spaceAround, spaceEvenly: how children share the main axis.
start, center, end, stretch: where children sit on the cross axis.
min shrinks the Row/Column to its children; max (default) fills the space.
Padding adds space around a child. SizedBox makes an empty gap (or fixes a size). Spacer takes all free room in a Row or Column.
all(16), symmetric(horizontal: 12), only(left: 8), fromLTRB(l,t,r,b).Padding(
padding: const EdgeInsets.all(16), // space inside
child: Column(children: const [
Text('Title'),
SizedBox(height: 12), // gap between items
Text('Subtitle'),
SizedBox(height: 12),
Row(children: [
Text('Left'),
Spacer(), // pushes next to right edge
Text('Right'),
]),
]),
)Puts the child in the middle of the available space, both ways.
Align(alignment: Alignment.bottomRight, child: ...) puts it at any of 9 spots.
topLeft, topCenter, topRight, centerLeft, center, centerRight, bottomLeft, bottomCenter, bottomRight.
Container(alignment: Alignment.center) does the same without a separate widget.
Expanded makes a child take the free space left in the Row or Column. flex shares that space in a ratio: flex 1 and flex 2 means 1/3 and 2/3.
Row(children: [
Container(width: 60, height: 60, color: Colors.orange), // fixed 60
Expanded(
flex: 1, // 1 share
child: Container(height: 60, color: Colors.green),
),
Expanded(
flex: 2, // 2 shares
child: Container(height: 60, color: Colors.blue),
),
])Stack draws children on top of each other. Positioned places a child at exact distances from the edges. The last child is on top.
Stack(
children: [
Container(width: 200, height: 120, color: Colors.indigo.shade100),
Positioned(
top: 8, right: 8,
child: Icon(Icons.favorite, color: Colors.red),
),
Positioned(
bottom: 8, left: 8,
child: Text('Ranchi Falls', style: TextStyle(fontSize: 18)),
),
],
)A Row that is too wide overflows. A Wrap starts a new line instead, like text in a paragraph.
Gap between items in one line.
Gap between lines.
Tag chips, skills, size selectors (S M L XL), filter buttons.
On a real device this means overflow: a Row or Column is bigger than the space. Add Expanded, Wrap or a scroll view.
Often a widget has size 0 or sits in a space with no height. Check Expanded/Container sizes.
"Widget Inspector" shows each widget and its size. Switch on "Show guidelines".
Temporarily give containers bright colours to see their real size.
Widget box(String t, MainAxisAlignment a) => Container(
width: 100, height: 240, color: Colors.blue.shade50,
child: Column(mainAxisAlignment: a, children: [
Text(t, style: const TextStyle(fontWeight: FontWeight.bold)),
const Icon(Icons.star), const Icon(Icons.star),
]),
);
void main() {
runApp(MaterialApp(home: Scaffold(
body: Padding(
padding: const EdgeInsets.only(top: 60),
child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
box('start', MainAxisAlignment.start),
box('center', MainAxisAlignment.center),
box('between', MainAxisAlignment.spaceBetween),
]),
),
)));
}Widget dot(Color c) => Container(width: 40, height: 40, color: c);
Widget rowDemo(String label, MainAxisAlignment a) => Column(children: [
Text(label),
Container(
color: Colors.grey.shade200, margin: const EdgeInsets.all(8),
child: Row(mainAxisAlignment: a, children: [
dot(Colors.red), dot(Colors.green), dot(Colors.blue),
]),
),
]);
void main() {
runApp(MaterialApp(home: Scaffold(
body: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
rowDemo('spaceBetween', MainAxisAlignment.spaceBetween),
rowDemo('spaceAround', MainAxisAlignment.spaceAround),
rowDemo('spaceEvenly', MainAxisAlignment.spaceEvenly),
]),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
body: Padding(
padding: const EdgeInsets.all(24),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const SizedBox(height: 40),
const Text('Admission Form', style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold)),
const SizedBox(height: 6),
const Text('Fill all details carefully'),
const SizedBox(height: 24),
Container(height: 48, color: Colors.grey.shade300),
const SizedBox(height: 12),
Container(height: 48, color: Colors.grey.shade300),
const SizedBox(height: 24),
ElevatedButton(onPressed: () {}, child: const Text('Submit')),
]),
),
)));
}Widget spot(String t, Alignment a) => Container(
height: 120, margin: const EdgeInsets.fromLTRB(16, 12, 16, 0),
color: Colors.teal.shade50,
child: Align(alignment: a, child: Padding(
padding: const EdgeInsets.all(8), child: Text(t))),
);
void main() {
runApp(MaterialApp(home: Scaffold(
body: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
spot('topLeft', Alignment.topLeft),
spot('center', Alignment.center),
spot('bottomRight', Alignment.bottomRight),
]),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
body: Column(children: [
Container(height: 70, color: Colors.indigo, alignment: Alignment.center,
child: const Text('HEADER', style: TextStyle(color: Colors.white))),
Row(children: [
Expanded(flex: 1, child: Container(height: 60, color: Colors.orange, alignment: Alignment.center, child: const Text('1'))),
Expanded(flex: 2, child: Container(height: 60, color: Colors.green, alignment: Alignment.center, child: const Text('2'))),
]),
Expanded(child: Container(color: Colors.amber.shade100, alignment: Alignment.center,
child: const Text('BODY takes all the rest'))),
Container(height: 50, color: Colors.indigo, alignment: Alignment.center,
child: const Text('FOOTER', style: TextStyle(color: Colors.white))),
]),
)));
}Widget badgeIcon(IconData icon, int count) => Stack(
clipBehavior: Clip.none,
children: [
Icon(icon, size: 44, color: Colors.indigo),
Positioned(
right: -6, top: -4,
child: Container(
padding: const EdgeInsets.all(5),
decoration: const BoxDecoration(color: Colors.red, shape: BoxShape.circle),
child: Text('$count', style: const TextStyle(color: Colors.white, fontSize: 12)),
),
),
],
);
void main() {
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Ranchi Mart'), actions: [
Padding(padding: const EdgeInsets.only(right: 20), child: badgeIcon(Icons.shopping_cart, 3)),
]),
body: Center(child: badgeIcon(Icons.notifications, 12)),
)));
}void main() {
const skills = ['Flutter', 'Dart', 'Firebase', 'REST API', 'Provider',
'Git', 'SQLite', 'UI Design', 'Testing', 'Play Store'];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('My Skills')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Wrap(
spacing: 8,
runSpacing: 8,
children: skills.map((s) => Chip(
avatar: const Icon(Icons.check_circle, size: 18, color: Colors.green),
label: Text(s),
)).toList(),
),
),
)));
}Widget topBar() => Container(
height: 60, padding: const EdgeInsets.symmetric(horizontal: 12),
color: Colors.teal,
child: const Row(children: [
Icon(Icons.menu, color: Colors.white),
Spacer(),
Text('Ranchi Mart', style: TextStyle(color: Colors.white, fontSize: 20)),
Spacer(),
Icon(Icons.search, color: Colors.white),
SizedBox(width: 12),
Icon(Icons.shopping_cart, color: Colors.white),
]),
);
void main() {
runApp(MaterialApp(home: Scaffold(
body: Column(children: [
topBar(),
const Expanded(child: Center(child: Text('Page content'))),
Padding(padding: const EdgeInsets.all(12), child: Row(children: [
const Text('Total: Rs 855', style: TextStyle(fontSize: 18)),
const Spacer(),
ElevatedButton(onPressed: () {}, child: const Text('Pay now')),
])),
]),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
backgroundColor: Colors.grey.shade200,
body: Center(child: Container(
width: 240,
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16)),
clipBehavior: Clip.antiAlias,
child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
Stack(children: [
Image.network('https://example.com/shoes.jpg', width: 240, height: 150, fit: BoxFit.cover),
Positioned(top: 10, left: 10, child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
color: Colors.red, child: const Text('30% OFF', style: TextStyle(color: Colors.white, fontSize: 12)))),
const Positioned(top: 8, right: 8, child: Icon(Icons.favorite_border, color: Colors.white)),
]),
Padding(padding: const EdgeInsets.all(12), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const Text('Running Shoes', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const Row(children: [Icon(Icons.star, size: 16, color: Colors.amber), Text(' 4.5 (212)')]),
const SizedBox(height: 8),
Row(children: [
const Text('Rs 1,399', style: TextStyle(fontSize: 18, color: Colors.green)),
const SizedBox(width: 6),
const Text('Rs 1,999', style: TextStyle(decoration: TextDecoration.lineThrough, color: Colors.grey)),
const Spacer(),
Container(padding: const EdgeInsets.all(6), color: Colors.indigo, child: const Icon(Icons.add_shopping_cart, color: Colors.white, size: 20)),
]),
])),
]),
)),
)));
}Widget stat(String label, String value, Color c) => Expanded(child: Container(
margin: const EdgeInsets.all(6), padding: const EdgeInsets.all(12),
decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(14)),
child: Column(children: [
Text(value, style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: Colors.white)),
Text(label, style: const TextStyle(color: Colors.white70, fontSize: 12)),
]),
));
void main() {
runApp(MaterialApp(home: Scaffold(
body: Column(children: [
Container(
padding: const EdgeInsets.fromLTRB(16, 44, 16, 16),
decoration: const BoxDecoration(
gradient: LinearGradient(colors: [Colors.indigo, Colors.blue]),
borderRadius: BorderRadius.vertical(bottom: Radius.circular(24))),
child: Column(children: [
const Row(children: [
CircleAvatar(radius: 24, backgroundColor: Colors.white, child: Text('NK')),
SizedBox(width: 12),
Expanded(child: Text('Hello, Nandan!', style: TextStyle(color: Colors.white, fontSize: 22))),
Icon(Icons.notifications, color: Colors.white),
]),
const SizedBox(height: 14),
Row(children: [stat('Students', '128', Colors.white), stat('Batches', '6', Colors.white), stat('Fees due', '12', Colors.white)]),
]),
),
const Expanded(child: Center(child: Text('Today\'s classes appear here'))),
]),
)));
}Parent gives limits, child picks size, parent places it.
Main axis follows the widget; cross axis is the other one.
Padding, SizedBox and Spacer create room.
flex shares free space in a ratio.
Layers with Positioned for badges and overlays.
Starts a new line when the row is full.
Pay now, Sign in, Add to cart: each is a button with a different style.
Contact lists, settings pages, order history rows.
Filters like "Veg", profile pictures in a class group.
Every button needs onPressed: the code that runs on tap. null makes the button grey and disabled.
void main() {
runApp(MaterialApp(home: Scaffold(body: Center(child: Column(children: [
ElevatedButton(onPressed: () {}, child: const Text('Pay now')),
OutlinedButton(onPressed: () {}, child: const Text('Cancel')),
TextButton(onPressed: () {}, child: const Text('Forgot password?')),
IconButton(onPressed: () {}, icon: const Icon(Icons.favorite)),
ElevatedButton(onPressed: null, child: const Text('Disabled')),
])))));
}styleFrom changes colour, size and shape of a button without writing a whole theme.
void main() {
runApp(MaterialApp(home: Scaffold(body: Center(child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
),
child: const Text('Order now'),
)))));
}Loads a picture from the internet. Needs a width/height or a parent size.
Loads a picture stored inside your app (declare it in pubspec.yaml).
Cuts a child with rounded corners: ClipRRect(borderRadius: BorderRadius.circular(12), child: Image...).
A round picture or initials, used for profile photos.
Card is a rounded box with shadow. ListTile is a ready row: leading icon/photo, title, subtitle and trailing widget.
void main() {
runApp(MaterialApp(home: Scaffold(body: Center(child: Card(
elevation: 3,
margin: const EdgeInsets.all(12),
child: ListTile(
leading: const CircleAvatar(child: Text('R')),
title: const Text('Rohit Singh'),
subtitle: const Text('Class 10 - Ranchi'),
trailing: const Icon(Icons.call),
onTap: () {},
),
)))));
}A small label with optional icon: Chip(label: Text('Veg')).
A thin line between items: Divider() or Divider(thickness: 2).
Icon(Icons.home, size: 30, color: Colors.blue): over 2000 built-in icons.
A bar showing progress from 0 to 1: value: 0.7 means 70%.
TextStyle controls size, weight, colour and spacing. overflow: ellipsis shows "..." when text is too long.
void main() {
runApp(MaterialApp(home: Scaffold(body: Center(child: const Text(
'BrainBit Infotech',
style: TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
color: Colors.indigo,
letterSpacing: 1.5,
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
)))));
}void main() {
runApp(MaterialApp(home: Scaffold(
body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
ElevatedButton(onPressed: () {}, child: const Text('Pay now')),
const SizedBox(height: 10),
OutlinedButton(onPressed: () {}, child: const Text('Cancel')),
const SizedBox(height: 10),
TextButton(onPressed: () {}, child: const Text('Forgot password?')),
IconButton(onPressed: () {}, icon: const Icon(Icons.favorite, color: Colors.red)),
const ElevatedButton(onPressed: null, child: Text('Disabled')),
])),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
const CircleAvatar(radius: 44, backgroundColor: Colors.teal,
child: Text('AK', style: TextStyle(fontSize: 28, color: Colors.white))),
const SizedBox(height: 20),
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image.network('https://example.com/ranchi.jpg',
width: 220, height: 140, fit: BoxFit.cover),
),
])),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('My Contacts')),
body: Column(children: [
Card(margin: const EdgeInsets.fromLTRB(12, 12, 12, 0), child: ListTile(
leading: const CircleAvatar(child: Text('R')),
title: const Text('Rohit Singh'), subtitle: const Text('Doranda, Ranchi'),
trailing: const Icon(Icons.call, color: Colors.green))),
Card(margin: const EdgeInsets.fromLTRB(12, 8, 12, 0), child: ListTile(
leading: const CircleAvatar(child: Text('A')),
title: const Text('Asha Kumari'), subtitle: const Text('Kankarbagh, Patna'),
trailing: const Icon(Icons.call, color: Colors.green))),
]),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
body: Padding(padding: const EdgeInsets.all(20), child: Column(
crossAxisAlignment: CrossAxisAlignment.start, children: [
const SizedBox(height: 40),
const Text('Filter by diet', style: TextStyle(fontSize: 22)),
const SizedBox(height: 10),
const Wrap(spacing: 8, children: [
Chip(label: Text('Veg')), Chip(label: Text('Jain')), Chip(label: Text('Spicy')),
]),
const Divider(height: 32, thickness: 1.5),
const Text('Sort by', style: TextStyle(fontSize: 22)),
const SizedBox(height: 10),
const Wrap(spacing: 8, children: [
Chip(avatar: Icon(Icons.star, size: 16), label: Text('Rating')),
Chip(avatar: Icon(Icons.currency_rupee, size: 16), label: Text('Price')),
]),
])),
)));
}void main() {
const paid = 18000;
const total = 24000;
final percent = paid / total;
runApp(MaterialApp(home: Scaffold(
body: Padding(padding: const EdgeInsets.all(24), child: Column(
mainAxisAlignment: MainAxisAlignment.center, children: [
Text('Fees paid: Rs $paid of Rs $total'),
const SizedBox(height: 12),
LinearProgressIndicator(value: percent, minHeight: 12, color: Colors.green),
const SizedBox(height: 8),
Text('${(percent * 100).toStringAsFixed(0)}% complete'),
const SizedBox(height: 40),
const CircularProgressIndicator(),
const Text('Loading...'),
])),
)));
}Widget action(IconData i, String t, Color c) => Column(children: [
CircleAvatar(backgroundColor: c.withOpacity(0.15), child: Icon(i, color: c)),
const SizedBox(height: 4), Text(t, style: const TextStyle(fontSize: 12)),
]);
void main() {
runApp(MaterialApp(home: Scaffold(body: Center(child: Card(
margin: const EdgeInsets.all(20), elevation: 4,
child: Padding(padding: const EdgeInsets.all(20), child: Column(mainAxisSize: MainAxisSize.min, children: [
const CircleAvatar(radius: 40, child: Text('SK', style: TextStyle(fontSize: 26))),
const SizedBox(height: 12),
const Text('Sunita Kumari', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
const Text('Teacher, DAV School Ranchi'),
const Divider(height: 28),
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
action(Icons.call, 'Call', Colors.green), action(Icons.message, 'SMS', Colors.blue), action(Icons.mail, 'Email', Colors.red),
]),
])),
)))));
}Widget line(String n, int p) => Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Row(children: [Text(n), const Spacer(), Text('Rs $p')]),
);
void main() {
final items = {'Litti Chokha': 120, 'Dhuska': 60, 'Lassi': 40};
int total = 0;
items.forEach((k, v) => total += v);
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Order Bill')),
body: Padding(padding: const EdgeInsets.all(20), child: Column(children: [
...items.entries.map((e) => line(e.key, e.value)),
const Divider(thickness: 2),
Row(children: [
const Text('Total', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const Spacer(),
Text('Rs $total', style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.green)),
]),
])),
)));
}void main() {
final subjects = [
{'name': 'Flutter', 'done': 0.8},
{'name': 'Dart', 'done': 0.95},
{'name': 'Firebase', 'done': 0.35},
];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('My Progress')),
body: Padding(padding: const EdgeInsets.all(20), child: Column(
children: subjects.map((s) {
final d = s['done'] as double;
return Padding(padding: const EdgeInsets.only(bottom: 18), child: Column(
crossAxisAlignment: CrossAxisAlignment.start, children: [
Row(children: [Text(s['name'] as String), const Spacer(), Text('${(d * 100).toStringAsFixed(0)}%')]),
const SizedBox(height: 6),
LinearProgressIndicator(value: d, minHeight: 10),
]));
}).toList(),
)),
)));
}Widget stat(String v, String l) => Column(children: [
Text(v, style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white)),
Text(l, style: const TextStyle(color: Colors.white70, fontSize: 12)),
]);
Widget row(IconData i, String t) => Card(margin: const EdgeInsets.fromLTRB(16, 8, 16, 0),
child: ListTile(leading: Icon(i, color: Colors.indigo), title: Text(t), trailing: const Icon(Icons.chevron_right)));
void main() {
runApp(MaterialApp(home: Scaffold(body: Column(children: [
Container(width: double.infinity, padding: const EdgeInsets.fromLTRB(16, 48, 16, 20),
color: Colors.indigo, child: Column(children: [
const CircleAvatar(radius: 38, backgroundColor: Colors.white, child: Text('NK', style: TextStyle(fontSize: 24))),
const SizedBox(height: 10),
const Text('Nandan Kumar', style: TextStyle(color: Colors.white, fontSize: 22)),
const SizedBox(height: 14),
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [stat('128', 'Students'), stat('6', 'Batches'), stat('4.9', 'Rating')]),
])),
const SizedBox(height: 8),
row(Icons.person, 'Edit profile'), row(Icons.notifications, 'Notifications'),
row(Icons.lock, 'Privacy'), row(Icons.help, 'Help and support'),
]))));
}Widget dish(String e, String n, int p, bool veg) => Card(
margin: const EdgeInsets.fromLTRB(14, 8, 14, 0),
child: Padding(padding: const EdgeInsets.all(12), child: Row(children: [
Text(e, style: const TextStyle(fontSize: 36)),
const SizedBox(width: 12),
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(n, style: const TextStyle(fontSize: 17, fontWeight: FontWeight.bold)),
Chip(label: Text(veg ? 'Veg' : 'Non-veg'),
backgroundColor: veg ? Colors.green.shade100 : Colors.red.shade100),
])),
Column(children: [
Text('Rs $p', style: const TextStyle(fontSize: 16, color: Colors.green)),
ElevatedButton(onPressed: () {}, child: const Text('Add')),
]),
])),
);
void main() {
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Ranchi Rasoi')),
body: Column(children: [
dish('\u{1F35B}', 'Litti Chokha', 120, true),
dish('\u{1F357}', 'Chicken Curry', 220, false),
dish('\u{1F35A}', 'Dal Bhat', 90, true),
]),
)));
}Elevated for main, Outlined/Text for others, IconButton for icons.
Image.network/asset, ClipRRect for corners, CircleAvatar for photos.
Ready rows with four slots.
Small tags and filters.
LinearProgressIndicator(value) for percentages.
Big screens are small components combined.
WhatsApp chats, contact list, notification page.
Product grid in Amazon, photo gallery.
Story circles, category chips at the top of a shop.
A Column does not scroll and overflows. A ListView scrolls when it has more children than fit.
void main() {
runApp(MaterialApp(home: Scaffold(body: ListView(
children: const [
ListTile(leading: Icon(Icons.home), title: Text('Home')),
ListTile(leading: Icon(Icons.school), title: Text('Courses')),
ListTile(leading: Icon(Icons.person), title: Text('Profile')),
ListTile(leading: Icon(Icons.settings), title: Text('Settings')),
],
))));
}builder creates each row only when it scrolls into view. itemCount says how many, itemBuilder builds row number index.
final names = ['Rohit', 'Asha', 'Imran', 'Pooja'];
void main() {
runApp(MaterialApp(home: Scaffold(body: ListView.builder(
itemCount: names.length,
itemBuilder: (context, index) {
return ListTile(
leading: CircleAvatar(child: Text(names[index][0])),
title: Text(names[index]),
);
},
))));
}GridView.count makes a grid with a fixed number of columns. Change crossAxisCount to 3 and the grid re-flows.
void main() {
runApp(MaterialApp(home: Scaffold(body: GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
padding: const EdgeInsets.all(12),
children: List.generate(6, (i) => Container(
color: Colors.indigo.shade100,
alignment: Alignment.center,
child: Text('Item ${i + 1}'),
)),
))));
}ListView(scrollDirection: Axis.horizontal) scrolls sideways. Give it a fixed height.
Like builder, plus separatorBuilder to draw a Divider between rows.
Makes a ListView only as tall as its children. Needed inside a Column, but use it only for short lists.
Makes any Column scroll. Good for forms; not for long data lists.
ListView with children.
ListView.builder.
GridView.count or GridView.builder.
SingleChildScrollView + Column.
Wrap a list with RefreshIndicator (more in Module 14).
void main() {
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Menu')),
body: ListView(children: const [
ListTile(leading: Icon(Icons.home), title: Text('Home')),
ListTile(leading: Icon(Icons.school), title: Text('My Courses')),
ListTile(leading: Icon(Icons.assignment), title: Text('Assignments')),
ListTile(leading: Icon(Icons.payment), title: Text('Fees')),
ListTile(leading: Icon(Icons.event), title: Text('Attendance')),
ListTile(leading: Icon(Icons.notifications), title: Text('Notices')),
ListTile(leading: Icon(Icons.person), title: Text('Profile')),
ListTile(leading: Icon(Icons.settings), title: Text('Settings')),
ListTile(leading: Icon(Icons.logout), title: Text('Log out')),
]),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Class 10-A')),
body: ListView.builder(
itemCount: 50,
itemBuilder: (context, i) => ListTile(
leading: CircleAvatar(child: Text('${i + 1}')),
title: Text('Student roll no ${i + 1}'),
),
),
)));
}void main() {
final people = ['Rohit Singh', 'Asha Kumari', 'Imran Ansari', 'Pooja Oraon', 'Suresh Mahto', 'Anita Devi'];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Contacts')),
body: ListView.builder(
itemCount: people.length,
itemBuilder: (context, i) => ListTile(
leading: CircleAvatar(child: Text(people[i][0])),
title: Text(people[i]),
subtitle: Text('98765${10000 + i * 111}'),
trailing: const Icon(Icons.call, color: Colors.green),
),
),
)));
}void main() {
final colors = [Colors.red, Colors.orange, Colors.green, Colors.blue, Colors.purple, Colors.teal, Colors.pink, Colors.indigo];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Gallery')),
body: GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 10, mainAxisSpacing: 10,
padding: const EdgeInsets.all(12),
children: List.generate(8, (i) => Container(
decoration: BoxDecoration(color: colors[i], borderRadius: BorderRadius.circular(12)),
alignment: Alignment.center,
child: Text('Photo ${i + 1}', style: const TextStyle(color: Colors.white, fontSize: 18)),
)),
),
)));
}void main() {
const cats = ['Mobiles', 'Fashion', 'Grocery', 'Books', 'Toys', 'Sports', 'Home'];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Ranchi Mart')),
body: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const Padding(padding: EdgeInsets.all(14), child: Text('Shop by category', style: TextStyle(fontSize: 20))),
SizedBox(height: 56, child: ListView.builder(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 10),
itemCount: cats.length,
itemBuilder: (c, i) => Padding(padding: const EdgeInsets.only(right: 8), child: Chip(label: Text(cats[i]))),
)),
]),
)));
}void main() {
final orders = {'Order #1021': 450, 'Order #1020': 1299, 'Order #1019': 220, 'Order #1018': 89, 'Order #1017': 640};
final keys = orders.keys.toList();
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('My Orders')),
body: ListView.separated(
itemCount: keys.length,
separatorBuilder: (c, i) => const Divider(height: 1),
itemBuilder: (c, i) => ListTile(
leading: const Icon(Icons.shopping_bag, color: Colors.indigo),
title: Text(keys[i]),
subtitle: const Text('Delivered'),
trailing: Text('Rs ${orders[keys[i]]}'),
),
),
)));
}void main() {
final products = [['School Bag', 649], ['Water Bottle', 199], ['Notebook Set', 120], ['Geometry Box', 85], ['Lunch Box', 249], ['Pen Pack', 60]];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Stationery Shop')),
body: GridView.builder(
padding: const EdgeInsets.all(12),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, crossAxisSpacing: 10, mainAxisSpacing: 10, childAspectRatio: 0.85),
itemCount: products.length,
itemBuilder: (c, i) => Card(child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
const Icon(Icons.inventory_2, size: 42, color: Colors.indigo),
const SizedBox(height: 8),
Text(products[i][0] as String, style: const TextStyle(fontWeight: FontWeight.bold)),
Text('Rs ${products[i][1]}', style: const TextStyle(color: Colors.green)),
])),
),
)));
}void main() {
final paragraph = 'Ranchi is the capital of Jharkhand. It is known as the City of Waterfalls because of Hundru, Dassam and Jonha falls nearby. ';
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Know Ranchi')),
body: SingleChildScrollView(padding: const EdgeInsets.all(16), child: Column(
crossAxisAlignment: CrossAxisAlignment.start, children: [
Container(height: 140, color: Colors.teal.shade100, alignment: Alignment.center, child: const Icon(Icons.landscape, size: 60)),
const SizedBox(height: 12),
const Text('City of Waterfalls', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
const SizedBox(height: 8),
Text(paragraph * 6),
const SizedBox(height: 12),
Center(child: ElevatedButton(onPressed: () {}, child: const Text('Share article'))),
])),
)));
}Widget bubble(String t, bool me) => Align(
alignment: me ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
padding: const EdgeInsets.all(10),
constraints: const BoxConstraints(maxWidth: 220),
decoration: BoxDecoration(
color: me ? Colors.green.shade200 : Colors.grey.shade300,
borderRadius: BorderRadius.circular(14)),
child: Text(t),
),
);
void main() {
final msgs = [['Hi Rohit, class at 5?', true], ['Yes sir, I will come', false], ['Bring your laptop', true], ['Ok sir', false]];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Rohit Singh')),
body: Column(children: [
Expanded(child: ListView.builder(
padding: const EdgeInsets.only(top: 10),
itemCount: msgs.length,
itemBuilder: (c, i) => bubble(msgs[i][0] as String, msgs[i][1] as bool),
)),
Padding(padding: const EdgeInsets.all(8), child: Row(children: [
Expanded(child: Container(padding: const EdgeInsets.all(12),
decoration: BoxDecoration(color: Colors.grey.shade200, borderRadius: BorderRadius.circular(24)),
child: const Text('Type a message'))),
const SizedBox(width: 8),
const CircleAvatar(child: Icon(Icons.send)),
])),
]),
)));
}void main() {
const cats = ['All', 'Sports', 'Weather', 'Education', 'Jobs', 'Business'];
final news = [['Ranchi gets a new flyover', 'City'], ['JSCA match tickets open', 'Sports'], ['Heavy rain alert for Jharkhand', 'Weather'], ['Board results announced', 'Education'], ['Walk-in drive at Namkum', 'Jobs']];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Ranchi Samachar')),
body: Column(children: [
SizedBox(height: 52, child: ListView.builder(
scrollDirection: Axis.horizontal, padding: const EdgeInsets.all(8), itemCount: cats.length,
itemBuilder: (c, i) => Padding(padding: const EdgeInsets.only(right: 8),
child: Chip(label: Text(cats[i]), backgroundColor: i == 0 ? Colors.indigo.shade100 : null)),
)),
Expanded(child: ListView.builder(
itemCount: news.length,
itemBuilder: (c, i) => Card(margin: const EdgeInsets.fromLTRB(12, 4, 12, 4), child: ListTile(
leading: Container(width: 56, height: 56, color: Colors.indigo.shade50, child: const Icon(Icons.article)),
title: Text(news[i][0]), subtitle: Text(news[i][1]),
trailing: const Icon(Icons.bookmark_border),
)),
)),
]),
)));
}Scrolls when content is too long.
Builds rows on demand from data: fast for large lists.
count / builder for tiles in columns.
scrollDirection + fixed height.
Fixes lists inside a Column.
For pages and forms.