Long lists that scroll smoothly · 5 h
Collapsing headers and swipeable pages · 5 h
Show data clearly · 5 h
Every way a user can tap, type and choose · 6 h
A scrolling column. Use it for a few widgets.
Builds rows on demand. Use it for long or unknown-length lists.
Rows and columns, like a photo gallery or category menu.
A Column cannot scroll. A ListView can. Put your widgets in children and the user can swipe.
void main() {
runApp(const MaterialApp(home: Scaffold(
body: ListView(children: [
ListTile(leading: Icon(Icons.train), title: Text('Ranchi Junction'), subtitle: Text('Platform 1')),
ListTile(leading: Icon(Icons.train), title: Text('Hatia'), subtitle: Text('Platform 2')),
ListTile(leading: Icon(Icons.train), title: Text('Tatisilwai'), subtitle: Text('Platform 1')),
ListTile(leading: Icon(Icons.train), title: Text('Muri'), subtitle: Text('Platform 3')),
ListTile(leading: Icon(Icons.train), title: Text('Bokaro Steel City'), subtitle: Text('Platform 1')),
ListTile(leading: Icon(Icons.train), title: Text('Dhanbad'), subtitle: Text('Platform 4')),
ListTile(leading: Icon(Icons.train), title: Text('Gaya Junction'), subtitle: Text('Platform 2')),
]),
)));
}For long lists, give itemCount and an itemBuilder. Flutter calls the builder only for rows near the screen, and re-uses them when you scroll.
void main() {
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Roll numbers')),
body: ListView.builder(
itemCount: 500,
itemBuilder: (context, index) {
return ListTile(
leading: CircleAvatar(child: Text('${index + 1}')),
title: Text('Student ${index + 1}'),
);
},
),
)));
}ListView.separated adds a divider between rows with separatorBuilder. Set scrollDirection: Axis.horizontal to scroll sideways, such as a row of stories or categories.
void main() {
runApp(MaterialApp(home: Scaffold(
body: Column(children: [
SizedBox(height: 90, child: ListView.builder(
scrollDirection: Axis.horizontal, itemCount: 8,
itemBuilder: (c, i) => Container(width: 70, margin: const EdgeInsets.all(8), decoration: BoxDecoration(color: Colors.primaries[i % 10].shade200, shape: BoxShape.circle), child: Center(child: Text('${i + 1}'))),
)),
Expanded(child: ListView.separated(
itemCount: 6,
separatorBuilder: (c, i) => const Divider(),
itemBuilder: (c, i) => ListTile(title: Text('Message ${i + 1}')),
)),
]),
)));
}GridView.count sets the number of columns. GridView.extent sets the maximum width of one cell, so the number of columns changes with the screen. GridView.builder is the lazy version for long grids.
void main() {
runApp(MaterialApp(home: Scaffold(
body: GridView.count(
crossAxisCount: 3, mainAxisSpacing: 8, crossAxisSpacing: 8, padding: const EdgeInsets.all(12),
children: [
for (var i = 0; i < 12; i++) Container(
decoration: BoxDecoration(color: Colors.teal.shade100, borderRadius: BorderRadius.circular(12)),
child: Center(child: Text('Item ${i + 1}')),
),
],
),
)));
}A ScrollController tells you how far the list has scrolled (offset) and lets you jump or animate. Use it for "back to top" buttons, hiding the app bar, or loading more items near the end.
dispose() in a real app so memory is freed.class Page extends StatefulWidget {
const Page({super.key});
@override
State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
final ctl = ScrollController();
bool showTop = false;
@override
void initState() {
super.initState();
ctl.addListener(() {
final s = ctl.offset > 200;
if (s != showTop) setState(() => showTop = s);
});
}
@override
Widget build(BuildContext context) => Scaffold(
body: ListView.builder(controller: ctl, itemCount: 60, itemBuilder: (c, i) => ListTile(title: Text('Row $i'))),
floatingActionButton: showTop
? FloatingActionButton(onPressed: () => ctl.animateTo(0, duration: const Duration(milliseconds: 400), curve: Curves.easeOut), child: const Icon(Icons.arrow_upward))
: null,
);
}
void main() => runApp(const MaterialApp(home: Page()));void main() {
runApp(const MaterialApp(home: Scaffold(
appBar: AppBar(title: Text('Contacts')),
body: ListView(children: [
ListTile(leading: CircleAvatar(child: Text('A')), title: Text('Asha Kumari'), subtitle: Text('Ranchi'), trailing: Icon(Icons.call)),
ListTile(leading: CircleAvatar(child: Text('R')), title: Text('Ravi Oraon'), subtitle: Text('Gumla'), trailing: Icon(Icons.call)),
ListTile(leading: CircleAvatar(child: Text('M')), title: Text('Meena Devi'), subtitle: Text('Patna'), trailing: Icon(Icons.call)),
ListTile(leading: CircleAvatar(child: Text('S')), title: Text('Sunil Mahto'), subtitle: Text('Dhanbad'), trailing: Icon(Icons.call)),
]),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Class 10-A attendance')),
body: ListView.builder(
itemCount: 100,
itemBuilder: (context, i) => ListTile(
leading: CircleAvatar(child: Text('${i + 1}')),
title: Text('Student ${i + 1}'),
trailing: Icon(i % 7 == 0 ? Icons.cancel : Icons.check_circle, color: i % 7 == 0 ? Colors.red : Colors.green),
),
),
)));
}void main() {
final items = ['Profile', 'Notifications', 'Language', 'Privacy', 'Help', 'About'];
runApp(MaterialApp(home: Scaffold(
appBar: AppBar(title: const Text('Settings')),
body: ListView.separated(
itemCount: items.length,
separatorBuilder: (context, i) => const Divider(height: 1),
itemBuilder: (context, i) => ListTile(title: Text(items[i]), trailing: const Icon(Icons.chevron_right)),
),
)));
}void main() {
final cats = [['Grocery', Icons.shopping_basket, Colors.green], ['Mobiles', Icons.phone_android, Colors.blue], ['Fashion', Icons.checkroom, Colors.pink], ['Books', Icons.menu_book, Colors.orange], ['Toys', Icons.toys, Colors.purple], ['Home', Icons.chair, Colors.teal]];
runApp(MaterialApp(home: Scaffold(
body: GridView.count(
crossAxisCount: 3, padding: const EdgeInsets.all(16), mainAxisSpacing: 12, crossAxisSpacing: 12,
children: [
for (final c in cats) Container(
decoration: BoxDecoration(color: (c[2] as Color).withOpacity(0.12), borderRadius: BorderRadius.circular(16)),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [Icon(c[1] as IconData, size: 34, color: c[2] as Color), const SizedBox(height: 6), Text(c[0] as String)]),
),
],
),
)));
}void main() {
final names = ['Asha', 'Ravi', 'Meena', 'Sunil', 'Pooja', 'Amit', 'Kajal', 'Vikas'];
runApp(MaterialApp(home: Scaffold(
body: SafeArea(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const Padding(padding: EdgeInsets.all(16), child: Text('Stories', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold))),
SizedBox(height: 100, child: ListView.builder(
scrollDirection: Axis.horizontal, padding: const EdgeInsets.symmetric(horizontal: 8), itemCount: names.length,
itemBuilder: (c, i) => Column(children: [
Container(width: 64, height: 64, margin: const EdgeInsets.symmetric(horizontal: 8), decoration: BoxDecoration(shape: BoxShape.circle, border: Border.all(color: Colors.pink, width: 3), color: Colors.pink.shade50), child: Center(child: Text(names[i][0], style: const TextStyle(fontSize: 22)))),
Text(names[i], style: const TextStyle(fontSize: 12)),
]),
)),
])),
)));
}class Search extends StatefulWidget {
const Search({super.key});
@override
State<Search> createState() => _SearchState();
}
class _SearchState extends State<Search> {
final all = ['Ranchi', 'Jamshedpur', 'Dhanbad', 'Bokaro', 'Hazaribagh', 'Deoghar', 'Giridih', 'Ramgarh', 'Chaibasa', 'Dumka', 'Pakur', 'Lohardaga'];
String q = '';
@override
Widget build(BuildContext context) {
final list = all.where((e) => e.toLowerCase().contains(q.toLowerCase())).toList();
return Scaffold(
appBar: AppBar(title: const Text('Jharkhand towns')),
body: Column(children: [
Padding(padding: const EdgeInsets.all(12), child: TextField(
decoration: const InputDecoration(prefixIcon: Icon(Icons.search), hintText: 'Search town', border: OutlineInputBorder()),
onChanged: (v) => setState(() => q = v),
)),
Expanded(child: list.isEmpty
? const Center(child: Text('No town found'))
: ListView.builder(itemCount: list.length, itemBuilder: (c, i) => ListTile(title: Text(list[i])))),
]),
);
}
}
void main() => runApp(const MaterialApp(home: Search()));class Pick extends StatefulWidget {
const Pick({super.key});
@override
State<Pick> createState() => _PickState();
}
class _PickState extends State<Pick> {
final sel = <int>{};
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text(sel.isEmpty ? 'Select photos' : '${sel.length} selected')),
body: GridView.builder(
padding: const EdgeInsets.all(8),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, mainAxisSpacing: 6, crossAxisSpacing: 6),
itemCount: 24,
itemBuilder: (c, i) => GestureDetector(
onTap: () => setState(() { if (sel.contains(i)) { sel.remove(i); } else { sel.add(i); } }),
child: Stack(children: [
Container(decoration: BoxDecoration(color: Colors.primaries[i % 10].shade200, borderRadius: BorderRadius.circular(8))),
if (sel.contains(i)) Container(decoration: BoxDecoration(color: Colors.black38, borderRadius: BorderRadius.circular(8))),
if (sel.contains(i)) const Positioned(top: 6, right: 6, child: Icon(Icons.check_circle, color: Colors.white)),
]),
),
),
);
}
void main() => runApp(const MaterialApp(home: Pick()));class Feed extends StatefulWidget {
const Feed({super.key});
@override
State<Feed> createState() => _FeedState();
}
class _FeedState extends State<Feed> {
final ctl = ScrollController();
bool top = false;
@override
void initState() {
super.initState();
ctl.addListener(() {
final s = ctl.offset > 200;
if (s != top) setState(() => top = s);
});
}
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Ranchi Samachar')),
body: ListView.builder(controller: ctl, itemCount: 80, itemBuilder: (c, i) => ListTile(leading: const Icon(Icons.article), title: Text('News headline number ${i + 1}'))),
floatingActionButton: top ? FloatingActionButton.small(onPressed: () => ctl.animateTo(0, duration: const Duration(milliseconds: 400), curve: Curves.easeOut), child: const Icon(Icons.arrow_upward)) : null,
);
}
void main() => runApp(const MaterialApp(home: Feed()));class Infinite extends StatefulWidget {
const Infinite({super.key});
@override
State<Infinite> createState() => _InfiniteState();
}
class _InfiniteState extends State<Infinite> {
final ctl = ScrollController();
final items = List.generate(20, (i) => 'Post ${i + 1}');
bool loading = false;
@override
void initState() {
super.initState();
ctl.addListener(() {
if (!loading && ctl.position.pixels > ctl.position.maxScrollExtent - 200) {
setState(() => loading = true);
Future.delayed(const Duration(milliseconds: 600), () {
setState(() {
items.addAll(List.generate(20, (i) => 'Post ${items.length + i + 1}'));
loading = false;
});
});
}
});
}
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text('Feed (${items.length} posts)')),
body: ListView.builder(
controller: ctl, itemCount: items.length + 1,
itemBuilder: (c, i) => i < items.length
? ListTile(title: Text(items[i]), subtitle: const Text('Posted from Ranchi'))
: const Padding(padding: EdgeInsets.all(16), child: Center(child: CircularProgressIndicator())),
),
);
}
void main() => runApp(const MaterialApp(home: Infinite()));class Group extends StatelessWidget {
const Group({super.key});
@override
Widget build(BuildContext context) {
final data = {
'Ranchi': ['Kanke', 'Namkum', 'Bundu', 'Ormanjhi'],
'Dhanbad': ['Jharia', 'Govindpur'],
'Bokaro': ['Chas', 'Bermo', 'Chandankiyari'],
};
final rows = <Object>[];
data.forEach((k, v) { rows.add(k); rows.addAll(v); });
return Scaffold(
appBar: AppBar(title: const Text('Blocks by district')),
body: ListView.builder(
itemCount: rows.length,
itemBuilder: (c, i) {
final r = rows[i];
if (data.containsKey(r)) {
return Container(color: Colors.indigo.shade50, padding: const EdgeInsets.fromLTRB(16, 10, 16, 10),
child: Text(r as String, style: const TextStyle(fontWeight: FontWeight.bold, color: Colors.indigo)));
}
return ListTile(dense: true, leading: const Icon(Icons.location_on_outlined), title: Text(r as String));
},
),
);
}
}
void main() => runApp(const MaterialApp(home: Group()));A scrolling Column for a few widgets.
Builds visible rows only: fast for long lists.
Dividers between rows.
count, extent and builder for grids.
Axis.horizontal needs a fixed height.
Back-to-top and infinite scroll.
A piece of a scrollable area: a bar, a list, a grid or any box.
Holds many slivers and scrolls them as one page.
Swipe left and right, one full page at a time.
A ListView can hold only a list. A CustomScrollView holds many slivers, so a header, a grid and a list can all scroll together as one page.
void main() {
runApp(MaterialApp(home: Scaffold(
body: CustomScrollView(slivers: [
const SliverToBoxAdapter(child: Padding(padding: EdgeInsets.all(16), child: Text('Today in Ranchi', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)))),
SliverList(delegate: SliverChildBuilderDelegate(
(context, i) => ListTile(leading: const Icon(Icons.event), title: Text('Event ${i + 1}')),
childCount: 12,
)),
]),
)));
}expandedHeight sets the big size. pinned: true keeps a small bar visible after scrolling. flexibleSpace holds the background and title.
void main() {
runApp(MaterialApp(home: Scaffold(
body: CustomScrollView(slivers: [
SliverAppBar(
pinned: true, expandedHeight: 180, backgroundColor: Colors.teal,
flexibleSpace: FlexibleSpaceBar(
title: const Text('Betla National Park'),
background: Container(decoration: const BoxDecoration(gradient: LinearGradient(colors: [Color(0xFF134E5E), Color(0xFF71B280)], begin: Alignment.topCenter, end: Alignment.bottomCenter))),
),
),
SliverList(delegate: SliverChildBuilderDelegate((c, i) => ListTile(title: Text('Fact ${i + 1}')), childCount: 20)),
]),
)));
}PageView shows one page at a time and snaps when you swipe. A PageController lets your code jump to a page, and onPageChanged tells you which page is showing.
class Pages extends StatefulWidget {
const Pages({super.key});
@override
State<Pages> createState() => _PagesState();
}
class _PagesState extends State<Pages> {
final ctl = PageController();
int page = 0;
@override
Widget build(BuildContext context) => Scaffold(
body: Column(children: [
Expanded(child: PageView(
controller: ctl,
onPageChanged: (i) => setState(() => page = i),
children: [
Container(color: Colors.orange.shade200, child: const Center(child: Text('Page 1'))),
Container(color: Colors.green.shade200, child: const Center(child: Text('Page 2'))),
Container(color: Colors.blue.shade200, child: const Center(child: Text('Page 3'))),
],
)),
Padding(padding: const EdgeInsets.all(12), child: Text('Now on page ${page + 1}')),
]),
);
}
void main() => runApp(const MaterialApp(home: Pages()));void main() {
runApp(MaterialApp(home: Scaffold(
body: PageView(children: [
Container(color: Colors.orange.shade300, child: const Center(child: Text('Learn', style: TextStyle(fontSize: 36, color: Colors.white)))),
Container(color: Colors.teal.shade300, child: const Center(child: Text('Practice', style: TextStyle(fontSize: 36, color: Colors.white)))),
Container(color: Colors.indigo.shade300, child: const Center(child: Text('Build', style: TextStyle(fontSize: 36, color: Colors.white)))),
]),
)));
}class Viewer extends StatefulWidget {
const Viewer({super.key});
@override
State<Viewer> createState() => _ViewerState();
}
class _ViewerState extends State<Viewer> {
int page = 0;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text('Photo ${page + 1} of 5')),
body: PageView.builder(
itemCount: 5, onPageChanged: (i) => setState(() => page = i),
itemBuilder: (c, i) => Container(margin: const EdgeInsets.all(16), decoration: BoxDecoration(color: Colors.primaries[i * 2].shade200, borderRadius: BorderRadius.circular(20)), child: Center(child: Text('Photo ${i + 1}', style: const TextStyle(fontSize: 28)))),
),
);
}
void main() => runApp(const MaterialApp(home: Viewer()));void main() {
runApp(MaterialApp(home: Scaffold(
body: CustomScrollView(slivers: [
SliverAppBar(pinned: true, expandedHeight: 160, backgroundColor: Colors.deepPurple, flexibleSpace: const FlexibleSpaceBar(title: Text('Hundru Falls'), background: ColoredBox(color: Colors.deepPurple))),
SliverList(delegate: SliverChildBuilderDelegate((c, i) => ListTile(leading: const Icon(Icons.water), title: Text('Visitor tip ${i + 1}')), childCount: 15)),
]),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
body: CustomScrollView(slivers: [
SliverToBoxAdapter(child: Container(
margin: const EdgeInsets.all(16), padding: const EdgeInsets.all(20), height: 120,
decoration: BoxDecoration(gradient: const LinearGradient(colors: [Colors.orange, Colors.deepOrange]), borderRadius: BorderRadius.circular(16)),
child: const Text('Chhath sale\nFlat 25% off', style: TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold)),
)),
SliverList(delegate: SliverChildBuilderDelegate((c, i) => ListTile(title: Text('Product ${i + 1}'), trailing: Text('Rs ${(i + 1) * 40}')), childCount: 15)),
]),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
body: CustomScrollView(slivers: [
const SliverToBoxAdapter(child: Padding(padding: EdgeInsets.all(16), child: Text('Categories', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)))),
SliverPadding(padding: const EdgeInsets.symmetric(horizontal: 16), sliver: SliverGrid.count(
crossAxisCount: 3, mainAxisSpacing: 10, crossAxisSpacing: 10,
children: [for (var i = 0; i < 9; i++) Container(decoration: BoxDecoration(color: Colors.primaries[i].shade100, borderRadius: BorderRadius.circular(12)), child: Center(child: Text('Cat ${i + 1}')))],
)),
]),
)));
}class Carousel extends StatefulWidget {
const Carousel({super.key});
@override
State<Carousel> createState() => _CarouselState();
}
class _CarouselState extends State<Carousel> {
final ctl = PageController(viewportFraction: 0.8);
int page = 0;
final offers = ['Diwali sweets 20% off', 'Free delivery in Ranchi', 'Buy 1 get 1 chai'];
@override
Widget build(BuildContext context) => Scaffold(
body: Center(child: SizedBox(height: 200, child: PageView.builder(
controller: ctl, itemCount: offers.length, onPageChanged: (i) => setState(() => page = i),
itemBuilder: (c, i) => Container(
margin: EdgeInsets.symmetric(horizontal: 8, vertical: page == i ? 0 : 16),
decoration: BoxDecoration(color: Colors.primaries[i * 3 + 1].shade300, borderRadius: BorderRadius.circular(20)),
child: Center(child: Text(offers[i], textAlign: TextAlign.center, style: const TextStyle(fontSize: 22, color: Colors.white, fontWeight: FontWeight.bold))),
),
))),
);
}
void main() => runApp(const MaterialApp(home: Carousel()));class Onboard extends StatefulWidget {
const Onboard({super.key});
@override
State<Onboard> createState() => _OnboardState();
}
class _OnboardState extends State<Onboard> {
final ctl = PageController();
int page = 0;
final titles = ['Order food', 'Track delivery', 'Pay with UPI'];
@override
Widget build(BuildContext context) => Scaffold(
body: Column(children: [
Expanded(child: PageView.builder(
controller: ctl, itemCount: 3, onPageChanged: (i) => setState(() => page = i),
itemBuilder: (c, i) => Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
Icon([Icons.restaurant, Icons.delivery_dining, Icons.payments][i], size: 100, color: Colors.deepOrange),
const SizedBox(height: 20),
Text(titles[i], style: const TextStyle(fontSize: 28, fontWeight: FontWeight.bold)),
])),
)),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
for (var i = 0; i < 3; i++) Container(margin: const EdgeInsets.all(4), width: page == i ? 22 : 8, height: 8, decoration: BoxDecoration(color: page == i ? Colors.deepOrange : Colors.grey.shade300, borderRadius: BorderRadius.circular(4))),
]),
Padding(padding: const EdgeInsets.all(20), child: SizedBox(width: double.infinity, child: ElevatedButton(
onPressed: () { if (page < 2) { ctl.nextPage(duration: const Duration(milliseconds: 300), curve: Curves.easeInOut); } },
child: Text(page < 2 ? 'Next' : 'Start'),
))),
]),
);
}
void main() => runApp(const MaterialApp(home: Onboard()));void main() {
runApp(MaterialApp(home: Scaffold(
body: CustomScrollView(slivers: [
const SliverAppBar(pinned: true, title: Text('Ranchi Bazaar'), actions: [Icon(Icons.shopping_cart), SizedBox(width: 12)]),
SliverToBoxAdapter(child: Container(height: 110, margin: const EdgeInsets.all(12), decoration: BoxDecoration(color: Colors.pink.shade200, borderRadius: BorderRadius.circular(16)), child: const Center(child: Text('Sale ends Sunday', style: TextStyle(fontSize: 22, color: Colors.white))))),
SliverPadding(padding: const EdgeInsets.symmetric(horizontal: 12), sliver: SliverGrid.count(
crossAxisCount: 4, mainAxisSpacing: 8, crossAxisSpacing: 8,
children: [for (var i = 0; i < 8; i++) Container(decoration: BoxDecoration(color: Colors.primaries[i + 2].shade100, shape: BoxShape.circle))],
)),
SliverList(delegate: SliverChildBuilderDelegate((c, i) => ListTile(leading: const Icon(Icons.shopping_bag), title: Text('Product ${i + 1}'), trailing: Text('Rs ${(i + 1) * 99}')), childCount: 12)),
]),
)));
}import 'dart:async';
class Auto extends StatefulWidget {
const Auto({super.key});
@override
State<Auto> createState() => _AutoState();
}
class _AutoState extends State<Auto> {
final ctl = PageController();
int page = 0;
Timer? timer;
final colors = [Colors.deepOrange, Colors.teal, Colors.indigo, Colors.pink];
@override
void initState() {
super.initState();
timer = Timer.periodic(const Duration(seconds: 2), (t) {
final next = (page + 1) % colors.length;
ctl.animateToPage(next, duration: const Duration(milliseconds: 400), curve: Curves.easeInOut);
});
}
@override
void dispose() { timer?.cancel(); super.dispose(); }
@override
Widget build(BuildContext context) => Scaffold(
body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
SizedBox(height: 180, child: PageView.builder(
controller: ctl, itemCount: colors.length, onPageChanged: (i) => setState(() => page = i),
itemBuilder: (c, i) => Container(margin: const EdgeInsets.all(12), decoration: BoxDecoration(color: colors[i], borderRadius: BorderRadius.circular(18)), child: Center(child: Text('Banner ${i + 1}', style: const TextStyle(color: Colors.white, fontSize: 28)))),
)),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [for (var i = 0; i < colors.length; i++) Container(margin: const EdgeInsets.all(3), width: 9, height: 9, decoration: BoxDecoration(shape: BoxShape.circle, color: page == i ? Colors.black87 : Colors.black26))]),
])),
);
}
void main() => runApp(const MaterialApp(home: Auto()));class Report extends StatefulWidget {
const Report({super.key});
@override
State<Report> createState() => _ReportState();
}
class _ReportState extends State<Report> {
final ctl = PageController();
int page = 0;
final tabs = ['Today', 'Week', 'Month'];
final sales = ['Rs 12,400', 'Rs 86,200', 'Rs 3,41,000'];
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Sales report')),
body: Column(children: [
Padding(padding: const EdgeInsets.all(12), child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
for (var i = 0; i < tabs.length; i++) Padding(padding: const EdgeInsets.symmetric(horizontal: 4), child: ChoiceChip(
label: Text(tabs[i]), selected: page == i,
onSelected: (v) => ctl.animateToPage(i, duration: const Duration(milliseconds: 300), curve: Curves.easeInOut),
)),
])),
Expanded(child: PageView.builder(
controller: ctl, itemCount: tabs.length, onPageChanged: (i) => setState(() => page = i),
itemBuilder: (c, i) => Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
Text(tabs[i], style: const TextStyle(fontSize: 20, color: Colors.grey)),
Text(sales[i], style: const TextStyle(fontSize: 38, fontWeight: FontWeight.bold)),
])),
)),
]),
);
}
void main() => runApp(const MaterialApp(home: Report()));Pieces of one scrolling area.
Collapsing or pinned header.
Lists and grids inside CustomScrollView.
Swipe one page at a time.
nextPage, jumpToPage, viewportFraction.
onPageChanged keeps indicators in sync.
The quickest way to show one record with icon, title and details.
Rows and columns that can be sorted and selected.
Shows progress through a multi-step process.
A Card is a rounded, slightly raised panel. A ListTile gives a ready layout (leading, title, subtitle, trailing). A Chip is a small label.
isThreeLine: true when the subtitle has two lines, so the tile gets the right height.void main() {
runApp(const MaterialApp(home: Scaffold(
body: Padding(padding: EdgeInsets.all(12), child: Column(children: [
Card(child: ListTile(
leading: CircleAvatar(child: Icon(Icons.person)),
title: Text('Asha Kumari'),
subtitle: Text('Class 10-A | Roll 14'),
trailing: Chip(label: Text('Pass')),
)),
Card(child: ListTile(
leading: CircleAvatar(child: Icon(Icons.person)),
title: Text('Ravi Oraon'),
subtitle: Text('Class 10-A | Roll 22'),
trailing: Chip(label: Text('Merit')),
)),
])),
)));
}Table is a simple grid for fixed data like a timetable. DataTable adds a header, number alignment, sorting and row selection.
void main() {
runApp(const MaterialApp(home: Scaffold(
body: SingleChildScrollView(child: Padding(padding: EdgeInsets.all(12), child: Column(children: [
DataTable(columns: [
DataColumn(label: Text('Subject')),
DataColumn(label: Text('Marks'), numeric: true),
], rows: [
DataRow(cells: [DataCell(Text('Maths')), DataCell(Text('92'))]),
DataRow(cells: [DataCell(Text('Science')), DataCell(Text('88'))]),
DataRow(cells: [DataCell(Text('English')), DataCell(Text('95'))]),
]),
]))),
)));
}ExpansionTile opens and closes its children when tapped, perfect for FAQ screens. ExpansionPanelList manages several panels together, so you can allow only one open at a time.
void main() {
runApp(const MaterialApp(home: Scaffold(
body: ListView(children: [
ExpansionTile(title: Text('How do I pay my fees?'), children: [Padding(padding: EdgeInsets.all(16), child: Text('Pay by UPI, card or cash at the school office.'))]),
ExpansionTile(title: Text('When do classes start?'), children: [Padding(padding: EdgeInsets.all(16), child: Text('Classes start at 8 AM, Monday to Saturday.'))]),
ExpansionTile(title: Text('Is there a school bus?'), initiallyExpanded: true, children: [Padding(padding: EdgeInsets.all(16), child: Text('Yes. Routes cover Kanke, Namkum and Hinoo.'))]),
]),
)));
}Stepper shows numbered steps, the current one expanded, with Continue and Cancel buttons. Use it for forms that have several parts, such as checkout.
class Steps extends StatefulWidget {
const Steps({super.key});
@override
State<Steps> createState() => _StepsState();
}
class _StepsState extends State<Steps> {
int step = 0;
@override
Widget build(BuildContext context) => Scaffold(
body: Stepper(
currentStep: step,
onStepContinue: () { if (step < 2) setState(() => step++); },
onStepCancel: () { if (step > 0) setState(() => step--); },
steps: const [
Step(title: Text('Address'), content: Text('Kanke Road, Ranchi')),
Step(title: Text('Payment'), content: Text('UPI')),
Step(title: Text('Confirm'), content: Text('Place order')),
],
),
);
}
void main() => runApp(const MaterialApp(home: Steps()));void main() {
runApp(const MaterialApp(home: Scaffold(
appBar: AppBar(title: Text('Alerts')),
body: Padding(padding: EdgeInsets.all(12), child: Column(children: [
Card(child: ListTile(leading: Icon(Icons.local_shipping, color: Colors.blue), title: Text('Order shipped'), subtitle: Text('Arrives at Kanke Road tomorrow'), trailing: Text('10:30'))),
Card(child: ListTile(leading: Icon(Icons.payments, color: Colors.green), title: Text('Payment received'), subtitle: Text('Rs 1,240 by UPI'), trailing: Text('09:12'))),
Card(child: ListTile(leading: Icon(Icons.warning, color: Colors.orange), title: Text('Low stock'), subtitle: Text('Atta 5 kg: 3 left'), trailing: Text('Yesterday'))),
])),
)));
}Widget c(String t, {bool head = false}) => Padding(padding: const EdgeInsets.all(10), child: Text(t, style: TextStyle(fontWeight: head ? FontWeight.bold : FontWeight.normal), textAlign: TextAlign.center));
void main() {
runApp(MaterialApp(home: Scaffold(
body: Padding(padding: const EdgeInsets.all(12), child: Table(
border: TableBorder.all(color: Colors.grey),
columnWidths: const {0: FixedColumnWidth(70)},
children: [
TableRow(decoration: BoxDecoration(color: Colors.indigo.shade50), children: [c('Day', head: true), c('Period 1', head: true), c('Period 2', head: true)]),
TableRow(children: [c('Mon'), c('Maths'), c('Science')]),
TableRow(children: [c('Tue'), c('Hindi'), c('English')]),
TableRow(children: [c('Wed'), c('Computer'), c('Sports')]),
],
)),
)));
}void main() {
runApp(const MaterialApp(home: Scaffold(
body: Padding(padding: EdgeInsets.only(top: 24), child: SingleChildScrollView(child: DataTable(
columns: [DataColumn(label: Text('Name')), DataColumn(label: Text('Maths'), numeric: true), DataColumn(label: Text('Science'), numeric: true)],
rows: [
DataRow(cells: [DataCell(Text('Asha')), DataCell(Text('92')), DataCell(Text('88'))]),
DataRow(cells: [DataCell(Text('Ravi')), DataCell(Text('75')), DataCell(Text('81'))]),
DataRow(cells: [DataCell(Text('Meena')), DataCell(Text('88')), DataCell(Text('94'))]),
],
))),
)));
}void main() {
runApp(const MaterialApp(home: Scaffold(
appBar: AppBar(title: Text('Help')),
body: ListView(children: [
ExpansionTile(title: Text('How to track my order?'), children: [ListTile(title: Text('Open My Orders and tap the order.'))]),
ExpansionTile(title: Text('Can I cancel an order?'), children: [ListTile(title: Text('Yes, before it is shipped.'))]),
ExpansionTile(title: Text('Cash on delivery available?'), children: [ListTile(title: Text('Yes in Ranchi, Hazaribagh and Dhanbad.'))]),
]),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
Wrap(spacing: 8, children: [
const Chip(avatar: Icon(Icons.local_offer, size: 18), label: Text('Sale')),
InputChip(label: const Text('Ranchi'), onDeleted: () {}),
ActionChip(label: const Text('Clear all'), onPressed: () {}),
]),
const SizedBox(height: 30),
Badge(label: const Text('5'), child: const Icon(Icons.mail, size: 40)),
])),
)));
}class Results extends StatefulWidget {
const Results({super.key});
@override
State<Results> createState() => _ResultsState();
}
class _ResultsState extends State<Results> {
final rows = [['Asha', 92], ['Ravi', 75], ['Meena', 88], ['Sunil', 69]];
int col = 0;
bool asc = true;
void sort(int c, bool a) {
rows.sort((x, y) => a ? Comparable.compare(x[c] as Comparable, y[c] as Comparable) : Comparable.compare(y[c] as Comparable, x[c] as Comparable));
setState(() { col = c; asc = a; });
}
@override
Widget build(BuildContext context) => Scaffold(
body: Padding(padding: const EdgeInsets.only(top: 30), child: DataTable(
sortColumnIndex: col, sortAscending: asc,
columns: [
DataColumn(label: const Text('Name'), onSort: sort),
DataColumn(label: const Text('Marks'), numeric: true, onSort: sort),
],
rows: [for (final r in rows) DataRow(cells: [DataCell(Text(r[0] as String)), DataCell(Text('${r[1]}'))])],
)),
);
}
void main() => runApp(const MaterialApp(home: Results()));class Admin extends StatefulWidget {
const Admin({super.key});
@override
State<Admin> createState() => _AdminState();
}
class _AdminState extends State<Admin> {
final people = ['Asha', 'Ravi', 'Meena', 'Sunil', 'Pooja'];
final sel = <String>{};
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text('${people.length} students'), actions: [
if (sel.isNotEmpty) IconButton(icon: const Icon(Icons.delete), onPressed: () => setState(() { people.removeWhere((p) => sel.contains(p)); sel.clear(); })),
]),
body: DataTable(
columns: const [DataColumn(label: Text('Name'))],
rows: [for (final p in people) DataRow(
selected: sel.contains(p),
onSelectChanged: (v) => setState(() { if (v == true) { sel.add(p); } else { sel.remove(p); } }),
cells: [DataCell(Text(p))],
)],
),
);
}
void main() => runApp(const MaterialApp(home: Admin()));class Syllabus extends StatefulWidget {
const Syllabus({super.key});
@override
State<Syllabus> createState() => _SyllabusState();
}
class _SyllabusState extends State<Syllabus> {
int open = 0;
final mods = const [['Module 1', 'Dart basics'], ['Module 2', 'Widgets and layouts'], ['Module 3', 'State and forms'], ['Module 4', 'APIs and storage']];
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Flutter syllabus')),
body: SingleChildScrollView(child: ExpansionPanelList(
expansionCallback: (i, isOpen) => setState(() => open = isOpen ? -1 : i),
children: [for (var i = 0; i < mods.length; i++) ExpansionPanel(
isExpanded: open == i, canTapOnHeader: true,
headerBuilder: (c, isOpen) => ListTile(title: Text(mods[i][0])),
body: Padding(padding: const EdgeInsets.fromLTRB(16, 0, 16, 16), child: Text(mods[i][1])),
)],
)),
);
}
void main() => runApp(const MaterialApp(home: Syllabus()));class Checkout extends StatefulWidget {
const Checkout({super.key});
@override
State<Checkout> createState() => _CheckoutState();
}
class _CheckoutState extends State<Checkout> {
int step = 0;
String pay = 'UPI';
bool done = false;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Checkout')),
body: done
? const Center(child: Text('Order placed! Thank you.', style: TextStyle(fontSize: 22)))
: Stepper(
currentStep: step,
onStepTapped: (i) => setState(() => step = i),
onStepContinue: () { if (step < 2) { setState(() => step++); } else { setState(() => done = true); } },
onStepCancel: () { if (step > 0) setState(() => step--); },
steps: [
const Step(title: Text('Address'), content: Text('12, Kanke Road, Ranchi 834006'), isActive: true),
Step(title: const Text('Payment'), isActive: step >= 1, content: Column(children: [
for (final m in ['UPI', 'Card', 'Cash on delivery']) RadioListTile<String>(title: Text(m), value: m, groupValue: pay, onChanged: (v) => setState(() => pay = v!)),
])),
Step(title: const Text('Confirm'), isActive: step >= 2, content: Text('Pay Rs 1,240 by $pay')),
],
),
);
}
void main() => runApp(const MaterialApp(home: Checkout()));class Timeline extends StatelessWidget {
const Timeline({super.key});
@override
Widget build(BuildContext context) {
final steps = [['Order placed', '18 Nov, 10:02'], ['Packed at Ranchi hub', '18 Nov, 16:40'], ['Out for delivery', '19 Nov, 09:15'], ['Delivered', 'Expected 19 Nov, 2 PM']];
const current = 2;
return Scaffold(
appBar: AppBar(title: const Text('Track order #1042')),
body: Padding(padding: const EdgeInsets.all(24), child: Column(children: [
for (var i = 0; i < steps.length; i++) IntrinsicHeight(child: Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Column(children: [
Container(width: 22, height: 22, decoration: BoxDecoration(shape: BoxShape.circle, color: i <= current ? Colors.green : Colors.grey.shade300),
child: i < current ? const Icon(Icons.check, size: 14, color: Colors.white) : null),
if (i < steps.length - 1) Expanded(child: Container(width: 3, color: i < current ? Colors.green : Colors.grey.shade300)),
]),
const SizedBox(width: 14),
Expanded(child: Padding(padding: const EdgeInsets.only(bottom: 26), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(steps[i][0], style: TextStyle(fontSize: 17, fontWeight: i == current ? FontWeight.bold : FontWeight.normal)),
Text(steps[i][1], style: const TextStyle(color: Colors.grey)),
]))),
])),
])),
);
}
}
void main() => runApp(const MaterialApp(home: Timeline()));One record, quickly.
Simple fixed grid.
Sort and select rows.
Hide details until tapped.
Guide a multi-step process.
Row + dot + line draws it.
Filled for the main action, outlined or text for the rest.
Checkbox, Radio, Switch, Slider: choose from known options.
TextField with label, hint, icon and keyboard type.
Material 3 has five main buttons. Use one filled button per screen for the main action and softer buttons for the rest.
onPressed: null. Flutter greys it out and ignores taps.void main() {
runApp(MaterialApp(home: Scaffold(
body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
FilledButton(onPressed: () {}, child: const Text('Pay now')),
const SizedBox(height: 10),
FilledButton.tonal(onPressed: () {}, child: const Text('Save draft')),
const SizedBox(height: 10),
OutlinedButton(onPressed: () {}, child: const Text('Cancel order')),
const SizedBox(height: 10),
TextButton(onPressed: () {}, child: const Text('Skip')),
const SizedBox(height: 10),
ElevatedButton.icon(onPressed: () {}, icon: const Icon(Icons.download), label: const Text('Download bill')),
])),
)));
}Use Checkbox for yes or no (many allowed), Radio for exactly one choice from a group, and Switch for turning something on or off immediately. Their ListTile versions give a bigger tap area with a label.
class Controls extends StatefulWidget {
const Controls({super.key});
@override
State<Controls> createState() => _ControlsState();
}
class _ControlsState extends State<Controls> {
bool agree = true, alerts = false;
String size = 'M';
@override
Widget build(BuildContext context) => Scaffold(
body: ListView(children: [
CheckboxListTile(title: const Text('I accept the terms'), value: agree, onChanged: (v) => setState(() => agree = v!)),
SwitchListTile(title: const Text('Order alerts'), value: alerts, onChanged: (v) => setState(() => alerts = v)),
for (final s in ['S', 'M', 'L']) RadioListTile<String>(title: Text('Size $s'), value: s, groupValue: size, onChanged: (v) => setState(() => size = v!)),
]),
);
}
void main() => runApp(const MaterialApp(home: Controls()));TextField collects text. InputDecoration adds a label, hint, icon, border and error text. A TextEditingController reads the text. keyboardType chooses the keyboard (number, email, phone).
phone.dispose() inside the dispose method.class Login extends StatefulWidget {
const Login({super.key});
@override
State<Login> createState() => _LoginState();
}
class _LoginState extends State<Login> {
final phone = TextEditingController();
final pass = TextEditingController();
String msg = '';
@override
Widget build(BuildContext context) => Scaffold(
body: Padding(padding: const EdgeInsets.all(20), child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
TextField(controller: phone, keyboardType: TextInputType.phone, decoration: const InputDecoration(labelText: 'Mobile number', prefixIcon: Icon(Icons.phone), border: OutlineInputBorder())),
const SizedBox(height: 14),
TextField(controller: pass, obscureText: true, decoration: const InputDecoration(labelText: 'Password', prefixIcon: Icon(Icons.lock), border: OutlineInputBorder())),
const SizedBox(height: 14),
FilledButton(onPressed: () => setState(() => msg = 'Logging in ${phone.text}'), child: const Text('Login')),
Text(msg),
])),
);
}
void main() => runApp(const MaterialApp(home: Login()));Slider / RangeSlider pick a number or a range. SegmentedButton picks one of a few options. DropdownButton picks from a longer list. showDatePicker and showTimePicker open the system pickers.
class Pick extends StatefulWidget {
const Pick({super.key});
@override
State<Pick> createState() => _PickState();
}
class _PickState extends State<Pick> {
RangeValues price = const RangeValues(200, 800);
String view = 'week';
String city = 'Ranchi';
@override
Widget build(BuildContext context) => Scaffold(
body: Padding(padding: const EdgeInsets.all(16), child: Column(children: [
Text('Price Rs ${price.start.round()} to ${price.end.round()}'),
RangeSlider(values: price, min: 0, max: 1000, onChanged: (v) => setState(() => price = v)),
SegmentedButton<String>(
segments: const [ButtonSegment(value: 'day', label: Text('Day')), ButtonSegment(value: 'week', label: Text('Week')), ButtonSegment(value: 'month', label: Text('Month'))],
selected: {view}, onSelectionChanged: (s) => setState(() => view = s.first),
),
DropdownButton<String>(value: city, items: ['Ranchi', 'Patna', 'Gaya'].map((c) => DropdownMenuItem(value: c, child: Text(c))).toList(), onChanged: (v) => setState(() => city = v!)),
Text('$view in $city'),
])),
);
}
void main() => runApp(const MaterialApp(home: Pick()));void main() {
runApp(MaterialApp(home: Scaffold(
body: Center(child: Padding(padding: const EdgeInsets.all(24), child: Row(children: [
Expanded(child: OutlinedButton(onPressed: () {}, child: const Text('Add to wishlist'))),
const SizedBox(width: 12),
Expanded(child: FilledButton(onPressed: () {}, child: const Text('Buy now'))),
]))),
)));
}void main() {
runApp(MaterialApp(home: Scaffold(
body: Center(child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.deepOrange, foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 16),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
textStyle: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
child: const Text('Order on WhatsApp'),
)),
)));
}class Consent extends StatefulWidget {
const Consent({super.key});
@override
State<Consent> createState() => _ConsentState();
}
class _ConsentState extends State<Consent> {
bool ok = false;
@override
Widget build(BuildContext context) => Scaffold(
body: Padding(padding: const EdgeInsets.all(24), child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
CheckboxListTile(value: ok, onChanged: (v) => setState(() => ok = v!), title: const Text('I accept the refund policy'), controlAffinity: ListTileControlAffinity.leading),
const SizedBox(height: 16),
FilledButton(onPressed: ok ? () {} : null, child: const Text('Pay Rs 499')),
])),
);
}
void main() => runApp(const MaterialApp(home: Consent()));class Settings extends StatefulWidget {
const Settings({super.key});
@override
State<Settings> createState() => _SettingsState();
}
class _SettingsState extends State<Settings> {
bool dark = false, notif = true, sound = true;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Settings')),
body: ListView(children: [
SwitchListTile(title: const Text('Dark mode'), value: dark, onChanged: (v) => setState(() => dark = v)),
SwitchListTile(title: const Text('Notifications'), subtitle: const Text('Order and offer alerts'), value: notif, onChanged: (v) => setState(() => notif = v)),
SwitchListTile(title: const Text('Sound'), value: sound, onChanged: (v) => setState(() => sound = v)),
]),
);
}
void main() => runApp(const MaterialApp(home: Settings()));void main() {
runApp(const MaterialApp(home: Scaffold(
body: Padding(padding: EdgeInsets.all(24), child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Text('Welcome back', style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold)),
SizedBox(height: 24),
TextField(keyboardType: TextInputType.emailAddress, decoration: InputDecoration(labelText: 'Email', hintText: 'name@example.com', prefixIcon: Icon(Icons.email), border: OutlineInputBorder())),
SizedBox(height: 14),
TextField(obscureText: true, decoration: InputDecoration(labelText: 'Password', prefixIcon: Icon(Icons.lock), suffixIcon: Icon(Icons.visibility), border: OutlineInputBorder())),
])),
)));
}class Form1 extends StatefulWidget {
const Form1({super.key});
@override
State<Form1> createState() => _Form1State();
}
class _Form1State extends State<Form1> {
String pay = 'UPI';
String cls = 'Class 8';
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Admission')),
body: ListView(padding: const EdgeInsets.all(16), children: [
const Text('Class', style: TextStyle(fontWeight: FontWeight.bold)),
DropdownButton<String>(
isExpanded: true, value: cls,
items: [for (var i = 1; i <= 12; i++) DropdownMenuItem(value: 'Class $i', child: Text('Class $i'))],
onChanged: (v) => setState(() => cls = v!),
),
const SizedBox(height: 16),
const Text('Fee payment', style: TextStyle(fontWeight: FontWeight.bold)),
for (final m in ['UPI', 'Net banking', 'Cash at school']) RadioListTile<String>(title: Text(m), value: m, groupValue: pay, onChanged: (v) => setState(() => pay = v!)),
Text('$cls, pay by $pay'),
]),
);
}
void main() => runApp(const MaterialApp(home: Form1()));class Seg extends StatefulWidget {
const Seg({super.key});
@override
State<Seg> createState() => _SegState();
}
class _SegState extends State<Seg> {
String range = 'week';
List<bool> fmt = [true, false, false];
@override
Widget build(BuildContext context) => Scaffold(
body: Center(child: Padding(padding: const EdgeInsets.all(20), child: Column(mainAxisSize: MainAxisSize.min, children: [
SegmentedButton<String>(
segments: const [ButtonSegment(value: 'day', label: Text('Day')), ButtonSegment(value: 'week', label: Text('Week')), ButtonSegment(value: 'month', label: Text('Month'))],
selected: {range}, onSelectionChanged: (s) => setState(() => range = s.first),
),
const SizedBox(height: 12),
Text('Sales for this $range', style: const TextStyle(fontSize: 18)),
const SizedBox(height: 30),
ToggleButtons(
isSelected: fmt, onPressed: (i) => setState(() => fmt[i] = !fmt[i]),
children: const [Icon(Icons.format_bold), Icon(Icons.format_italic), Icon(Icons.format_underlined)],
),
Text('Bold: ${fmt[0]} Italic: ${fmt[1]} Underline: ${fmt[2]}'),
]))),
);
}
void main() => runApp(const MaterialApp(home: Seg()));class Filter extends StatefulWidget {
const Filter({super.key});
@override
State<Filter> createState() => _FilterState();
}
class _FilterState extends State<Filter> {
RangeValues r = const RangeValues(200, 600);
final items = const [['Kurta', 450], ['Saree', 1800], ['T-shirt', 300], ['Jeans', 900], ['Dupatta', 250], ['Shirt', 650]];
@override
Widget build(BuildContext context) {
final shown = items.where((e) => (e[1] as int) >= r.start && (e[1] as int) <= r.end).toList();
return Scaffold(
appBar: AppBar(title: Text('Rs ${r.start.round()} - ${r.end.round()}')),
body: Column(children: [
RangeSlider(values: r, min: 0, max: 2000, divisions: 20, onChanged: (v) => setState(() => r = v)),
Expanded(child: ListView(children: [for (final e in shown) ListTile(title: Text(e[0] as String), trailing: Text('Rs ${e[1]}'))])),
]),
);
}
}
void main() => runApp(const MaterialApp(home: Filter()));class Book extends StatefulWidget {
const Book({super.key});
@override
State<Book> createState() => _BookState();
}
class _BookState extends State<Book> {
DateTime? date;
TimeOfDay? time;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Book appointment')),
body: Padding(padding: const EdgeInsets.all(20), child: Column(children: [
ListTile(
leading: const Icon(Icons.calendar_today), title: const Text('Date'),
subtitle: Text(date == null ? 'Tap to pick' : '${date!.day}/${date!.month}/${date!.year}'),
onTap: () async {
final d = await showDatePicker(context: context, initialDate: DateTime(2026, 11, 24), firstDate: DateTime(2026, 11, 1), lastDate: DateTime(2027, 3, 1));
if (d != null) setState(() => date = d);
},
),
ListTile(
leading: const Icon(Icons.access_time), title: const Text('Time'),
subtitle: Text(time == null ? 'Tap to pick' : time!.format(context)),
onTap: () async {
final t = await showTimePicker(context: context, initialTime: const TimeOfDay(hour: 10, minute: 30));
if (t != null) setState(() => time = t);
},
),
const SizedBox(height: 20),
FilledButton(onPressed: date != null && time != null ? () {} : null, child: const Text('Confirm booking')),
])),
);
}
void main() => runApp(const MaterialApp(home: Book()));class Reg extends StatefulWidget {
const Reg({super.key});
@override
State<Reg> createState() => _RegState();
}
class _RegState extends State<Reg> {
final name = TextEditingController();
String city = '';
bool terms = false;
static const cities = ['Ranchi', 'Patna', 'Jamshedpur', 'Dhanbad', 'Gaya', 'Bokaro', 'Muzaffarpur', 'Bhagalpur'];
@override
Widget build(BuildContext context) {
final ready = name.text.isNotEmpty && city.isNotEmpty && terms;
return Scaffold(
appBar: AppBar(title: const Text('Register')),
body: Padding(padding: const EdgeInsets.all(16), child: Column(children: [
TextField(controller: name, onChanged: (v) => setState(() {}), decoration: const InputDecoration(labelText: 'Full name', border: OutlineInputBorder())),
const SizedBox(height: 12),
const Align(alignment: Alignment.centerLeft, child: Padding(padding: EdgeInsets.only(bottom: 4), child: Text('City (type Ra)'))),
Autocomplete<String>(
optionsBuilder: (tv) => tv.text.isEmpty ? const Iterable<String>.empty() : cities.where((c) => c.toLowerCase().startsWith(tv.text.toLowerCase())),
onSelected: (s) => setState(() => city = s),
),
CheckboxListTile(value: terms, onChanged: (v) => setState(() => terms = v!), title: const Text('I agree to the terms')),
FilledButton(onPressed: ready ? () {} : null, child: const Text('Register')),
const SizedBox(height: 10),
Text(ready ? 'Ready: ${name.text} from $city' : 'Fill all fields'),
])),
);
}
}
void main() => runApp(const MaterialApp(home: Reg()));Filled, tonal, outlined, text, icon.
Checkbox, Radio, Switch keep value in state.
Decoration, controller, keyboardType.
Slider, RangeSlider, SegmentedButton.
await showDatePicker and showTimePicker.
Suggest values while typing.