FLUTTER WIDGETS & DESIGN COURSE · BRAINBIT INFOTECH

Part 2

4 modules · 21 class hours · 40 practical examples

Module 25: ListView, GridView and Scrolling

Long lists that scroll smoothly · 5 h

Module 26: Slivers, PageView and Carousels

Collapsing headers and swipeable pages · 5 h

Module 27: Data Display: Card, Table, DataTable, Stepper

Show data clearly · 5 h

Module 28: Buttons, Inputs and Selection Controls

Every way a user can tap, type and choose · 6 h

MODULE 25 · PART 2

ListView, GridView and Scrolling

Long lists that scroll smoothly
You will learn
  • Show many items with ListView and ListView.builder
  • Add dividers with ListView.separated
  • Build grids with GridView.count, extent and builder
  • Scroll sideways with horizontal lists
  • Control scrolling with ScrollController
You will build: contact lists, galleries and an infinite feed
5 class hours · 10 examples (5 Easy, 3 Medium, 2 Hard)
📜

Where is this used in real apps?

Contacts, chats, product catalogues, news feeds and photo galleries are all lists or grids. ListView.builder builds only the rows you can see, so even a list of 10,000 items stays fast.

ListView

A scrolling column. Use it for a few widgets.

ListView.builder

Builds rows on demand. Use it for long or unknown-length lists.

GridView

Rows and columns, like a photo gallery or category menu.

Contacts
👤
Asha Kumari
Ranchi
98xxxxx
👤
Ravi Oraon
Gumla
97xxxxx
👤
Meena Devi
Patna
96xxxxx
👤
Sunil Mahto
Dhanbad
95xxxxx
+

ListView: a scrolling Column

A Column cannot scroll. A ListView can. Put your widgets in children and the user can swipe.

Common error: putting a ListView directly inside a Column gives an "unbounded height" error. Wrap it in Expanded.
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')),
    ]),
  )));
}

ListView.builder: build on demand

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.

Rule: use the default ListView(children: ...) for 10 items or fewer. Use ListView.builder when the list is long or comes from the internet.
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 and horizontal lists

ListView.separated adds a divider between rows with separatorBuilder. Set scrollDirection: Axis.horizontal to scroll sideways, such as a row of stories or categories.

Horizontal list: it needs a fixed height (SizedBox). Without it Flutter cannot know how tall to make it.
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: rows and columns

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.

childAspectRatio is width divided by height. 1 means square, 0.75 means taller than wide.
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}')),
        ),
      ],
    ),
  )));
}

ScrollController: control the scroll

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.

Remember: dispose the controller in 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()));

Animated explainer: Why ListView.builder is fast

Press Next to walk through it step by step, or Auto play.

Animated explainer: Scroll anatomy: offset and extent

Press Next to walk through it step by step, or Auto play.
EASYReal project: phone book and chat listExample 1 of 10

Contact list

ListTile gives a ready layout with avatar, title, subtitle and trailing icon.
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)),
    ]),
  )));
}
Try it yourself: Add your own contact at the end.
Copy one ListTile and change the texts.
EASYReal project: attendance register, order historyExample 2 of 10

Roll number list with builder

ListView.builder creates 100 rows from one small piece of code. The index is the row number.
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),
      ),
    ),
  )));
}
Try it yourself: Make every 5th student absent instead of every 7th.
Change the % 7 to % 5.
EASYReal project: settings and message listsExample 3 of 10

Separated list

separatorBuilder draws a thin line between rows only, not after the last one.
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)),
    ),
  )));
}
Try it yourself: Add the item Logout.
Add it to the items list.
EASYReal project: home page category menuExample 4 of 10

Category grid

GridView.count with 3 columns makes the typical category menu. Each cell is an icon and a label.
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)]),
        ),
      ],
    ),
  )));
}
Try it yourself: Change to 2 columns.
Set crossAxisCount: 2.
EASYReal project: stories, category chips, bannersExample 5 of 10

Horizontal story strip

A horizontal ListView with a fixed height lets the user swipe sideways.
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)),
        ]),
      )),
    ])),
  )));
}
Try it yourself: Add three more names.
Add them to the names list.
MEDIUMReal project: contact search, product searchExample 6 of 10

Live search in a list

The text in the TextField is stored in state. build() filters the list with where, so every key press updates the result.
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()));
Try it yourself: Show the count: "5 results".
Add Text('${list.length} results') above the list.
MEDIUMReal project: gallery picker, product colour pickerExample 7 of 10

Multi-select photo grid

A Set in state stores selected indexes. GridView.builder draws each cell and shows a check mark when selected.
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()));
Try it yourself: Add a Clear button in the AppBar actions.
actions: [IconButton(icon: Icon(Icons.clear), onPressed: () => setState(() => sel.clear()))]
MEDIUMReal project: long feeds in news and social appsExample 8 of 10

Back-to-top button

A ScrollController listener turns a button on after 200 pixels. Tapping it animates the list back to the top.
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()));
Try it yourself: Show the scroll offset in the AppBar title.
Keep a double offset in state and update it in the listener.
HARDReal project: social feeds, product catalogues with pagingExample 9 of 10

Infinite scroll (load more)

When the user is within 200 pixels of the end, the listener adds the next 20 items. A real app would fetch them from a server page by page.
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()));
Try it yourself: Stop loading after 100 posts.
Add a check items.length < 100 before loading.
HARDReal project: contacts A-Z, orders by date, transactions by monthExample 10 of 10

Grouped list with section headers

Real lists often have headers. Flatten the data into one list where each entry is a header or an item, then use ListView.builder and check the type.
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()));
Try it yourself: Add a new district Hazaribagh with two blocks.
Add a key and a list of blocks to the data map.

Quick quiz

3 questions. Click an answer.
Which widget builds only visible rows?
ListView(children: ...)ListView.builderColumnWrap
What does childAspectRatio mean in a grid?
Number of columnsCell width divided by heightSpacingScroll speed
Which object tells you how far a list has scrolled?
ScrollControllerTextEditingControllerAnimationControllerTheme
Score: 0 / 3

Recap: what you learned in Module 25

ListView

A scrolling Column for a few widgets.

builder

Builds visible rows only: fast for long lists.

separated

Dividers between rows.

GridView

count, extent and builder for grids.

Horizontal

Axis.horizontal needs a fixed height.

ScrollController

Back-to-top and infinite scroll.

Next: Slivers, PageView and Carousels - Collapsing headers and swipeable pages
MODULE 26 · PART 2

Slivers, PageView and Carousels

Collapsing headers and swipeable pages
You will learn
  • Combine several scrolling parts in one CustomScrollView
  • Build collapsing headers with SliverAppBar
  • Use SliverList, SliverGrid and SliverToBoxAdapter
  • Swipe between pages with PageView and PageController
  • Make carousels with dot indicators
You will build: an onboarding flow, a banner carousel and a shop home page
5 class hours · 10 examples (5 Easy, 3 Medium, 2 Hard)
🎢

Where is this used in real apps?

Shopping home pages have a banner, a category grid and a product list that all scroll together. Onboarding screens and image carousels are PageViews.

Sliver

A piece of a scrollable area: a bar, a list, a grid or any box.

CustomScrollView

Holds many slivers and scrolls them as one page.

PageView

Swipe left and right, one full page at a time.

Shop Home
🎁
Diwali gifts
Up to 40% off
👕
Clothes
New arrivals
📱
Mobiles
Best prices
🍲
Sweets
Fresh today

CustomScrollView and slivers

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.

Rule: inside CustomScrollView use slivers only. A normal widget must go inside SliverToBoxAdapter.
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,
      )),
    ]),
  )));
}

SliverAppBar: a collapsing header

expandedHeight sets the big size. pinned: true keeps a small bar visible after scrolling. flexibleSpace holds the background and title.

Honest note: in the slide engine the bar fades its colour as you scroll. On a real phone the title also shrinks smoothly.
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 and PageController

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.

viewportFraction: 0.8 shows a bit of the next page on each side. That is the classic carousel look.
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()));

Animated explainer: Many slivers, one scroll

Press Next to walk through it step by step, or Auto play.

Animated explainer: How PageView and dots stay in sync

Press Next to walk through it step by step, or Auto play.
EASYReal project: intro screens, tutorial pagesExample 1 of 10

Swipe between three pages

PageView with three coloured pages. Swipe left and right with the mouse or finger.
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)))),
    ]),
  )));
}
Try it yourself: Add a fourth page called Earn.
Add another Container to children.
EASYReal project: photo viewer "3 of 5"Example 2 of 10

Page counter

PageView.builder creates pages from a number. onPageChanged keeps the counter updated.
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()));
Try it yourself: Change 5 to 8 photos.
Edit itemCount and the title text.
EASYReal project: profile and detail screensExample 3 of 10

Collapsing app bar

SliverAppBar with pinned: true shrinks to a normal bar and stays at the top while the list scrolls under it.
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)),
    ]),
  )));
}
Try it yourself: Change expandedHeight to 240.
Edit the number.
EASYReal project: home feed with a promo bannerExample 4 of 10

Banner above a list

SliverToBoxAdapter holds the banner; SliverList holds the items. Both scroll together.
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)),
    ]),
  )));
}
Try it yourself: Add a second banner below the first one.
Add another SliverToBoxAdapter.
EASYReal project: category grid on a shopping homeExample 5 of 10

Grid inside CustomScrollView

SliverGrid.count is the sliver version of GridView.count. Put it between other slivers.
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}')))],
      )),
    ]),
  )));
}
Try it yourself: Use 4 columns.
crossAxisCount: 4.
MEDIUMReal project: offer and movie carouselsExample 6 of 10

Peeking carousel

viewportFraction: 0.8 shows part of the next card, which hints that the user can swipe. The active card is bigger.
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()));
Try it yourself: Add a fourth offer.
Add a string to offers.
MEDIUMReal project: first-run screens in every appExample 7 of 10

Onboarding with Skip and Next

The PageController moves to the next page from a button. On the last page the button becomes Start. Dots show the position.
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()));
Try it yourself: Add a Skip text button that jumps to the last page.
ctl.jumpToPage(2).
MEDIUMReal project: Flipkart or Meesho style home pageExample 8 of 10

Shop home with mixed slivers

Four slivers in one scroll view: a pinned bar, a banner, a category grid and a product list. This is the most common real-world use of CustomScrollView.
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)),
    ]),
  )));
}
Try it yourself: Add a title sliver "Top deals" before the list.
Add SliverToBoxAdapter with a Text before SliverList.
HARDReal project: home-page banner that slides by itselfExample 9 of 10

Auto-play carousel with dots

A Timer.periodic moves to the next page every 2 seconds. animateToPage loops back to page 0 after the last one. Cancel the timer in dispose.
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()));
Try it yourself: Make it slide every 3 seconds.
Change seconds: 2 to 3.
HARDReal project: Today / Week / Month report switchExample 10 of 10

Segment chips linked to pages

Tapping a chip calls animateToPage. Swiping calls onPageChanged, which updates the chips. Both directions stay in sync.
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()));
Try it yourself: Add a fourth tab called Year.
Add to tabs and sales lists.

Quick quiz

3 questions. Click an answer.
Which widget lets a header, grid and list scroll together?
ColumnCustomScrollViewStackWrap
How do you place a normal widget inside a CustomScrollView?
DirectlyInside SliverToBoxAdapterWith PositionedYou cannot
What does onPageChanged give you?
The page number now showingThe scroll offsetThe colourNothing
Score: 0 / 3

Recap: what you learned in Module 26

Slivers

Pieces of one scrolling area.

SliverAppBar

Collapsing or pinned header.

SliverList / Grid

Lists and grids inside CustomScrollView.

PageView

Swipe one page at a time.

PageController

nextPage, jumpToPage, viewportFraction.

Dots

onPageChanged keeps indicators in sync.

Next: Data Display: Card, Table, DataTable, Stepper - Show data clearly
MODULE 27 · PART 2

Data Display: Card, Table, DataTable, Stepper

Show data clearly
You will learn
  • Show information in Card, ListTile and Chip
  • Build timetables with Table and sortable tables with DataTable
  • Hide and show details with ExpansionTile and ExpansionPanelList
  • Guide users through steps with Stepper
  • Draw a delivery timeline with plain widgets
You will build: a marks sheet, an FAQ and an order tracker
5 class hours · 10 examples (5 Easy, 3 Medium, 2 Hard)
📊

Where is this used in real apps?

School result sheets, FAQ pages, price lists, bank statements and order tracking screens all show data. The right widget makes the data easy to scan.

Card + ListTile

The quickest way to show one record with icon, title and details.

DataTable

Rows and columns that can be sorted and selected.

Stepper

Shows progress through a multi-step process.

Result Sheet
📝
Maths
Asha Kumari
92
📝
Science
Asha Kumari
88
📝
English
Asha Kumari
95

Card, ListTile and Chip

A Card is a rounded, slightly raised panel. A ListTile gives a ready layout (leading, title, subtitle, trailing). A Chip is a small label.

Tip: use 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 and DataTable

Table is a simple grid for fixed data like a timetable. DataTable adds a header, number alignment, sorting and row selection.

Wide tables: a DataTable is wider than a phone. Wrap it in a horizontal SingleChildScrollView to let the user swipe sideways.
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 and ExpansionPanelList

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.

State: ExpansionTile remembers its own open or closed state. With ExpansionPanelList you keep the state yourself.
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: steps in a process

Stepper shows numbered steps, the current one expanded, with Continue and Cancel buttons. Use it for forms that have several parts, such as checkout.

Honest note: the in-slide Stepper follows Material 3 look. Fine details such as animation timing differ slightly on a real phone.
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()));

Animated explainer: Choosing a data widget

Press Next to walk through it step by step, or Auto play.

Animated explainer: How DataTable sorting works

Press Next to walk through it step by step, or Auto play.
EASYReal project: alerts and message listsExample 1 of 10

Notification cards

Card + ListTile with a leading icon and a trailing time. Three lines of code per card.
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'))),
    ])),
  )));
}
Try it yourself: Add a fourth alert about rain.
Copy a Card and change the icon and text.
EASYReal project: timetable, price list, rate cardExample 2 of 10

School timetable with Table

Table aligns rows and columns without extra code. TableBorder.all draws the grid lines.
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')]),
      ],
    )),
  )));
}
Try it yourself: Add a row for Thursday.
Copy a TableRow.
EASYReal project: results, ledgers, price comparisonExample 3 of 10

Marks sheet with DataTable

numeric: true right-aligns number columns, which makes them easy to compare.
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'))]),
      ],
    ))),
  )));
}
Try it yourself: Add a column for English marks.
Add a DataColumn and a DataCell per row.
EASYReal project: help and FAQ screensExample 4 of 10

FAQ with ExpansionTile

Each tile hides its answer until tapped. The screen stays short and clean.
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.'))]),
    ]),
  )));
}
Try it yourself: Add a question about refunds.
Add another ExpansionTile.
EASYReal project: tags, filters, unread countsExample 5 of 10

Chips and a badge

Chip is a label, InputChip can be deleted, ActionChip can be tapped. Badge puts a small number on any widget.
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)),
    ])),
  )));
}
Try it yourself: Add a chip for Patna.
Add an InputChip.
MEDIUMReal project: student result and sales tablesExample 6 of 10

Sortable results table

Header taps call onSort. You sort the list and store the column index and direction in state. The arrow follows automatically.
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()));
Try it yourself: Add a third column "Grade" and make it sortable.
Add a DataColumn with onSort and a cell per row.
MEDIUMReal project: admin panels: delete selected students or ordersExample 7 of 10

Select rows and delete

Each DataRow has selected and onSelectChanged. A Set of ids in state holds the selection, and a button removes them.
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()));
Try it yourself: Show "n selected" in the AppBar title when something is selected.
Use sel.isEmpty ? ... : ...
MEDIUMReal project: course outline, product detailsExample 8 of 10

Syllabus accordion

ExpansionPanelList with an isExpanded list in state. Opening one panel can close the others, like an accordion.
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()));
Try it yourself: Allow two panels open by using a Set.
Replace open with a Set and toggle.
HARDReal project: address, payment and confirmation stepsExample 9 of 10

Checkout Stepper

A Stepper with state: Continue moves forward, Cancel goes back, tapping a step jumps to it. Each step content can be a real form.
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()));
Try it yourself: Add a step called Coupon between Address and Payment.
Add a Step in the list.
HARDReal project: order tracking, courier status, application statusExample 10 of 10

Delivery timeline from plain widgets

Not every design has a ready widget. A Row with a dot, a line and text, repeated in a loop, draws a timeline. Done steps are green and the active step is highlighted.
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()));
Try it yourself: Make "Delivered" the current step.
Set current = 3.

Quick quiz

3 questions. Click an answer.
Which widget is best for an FAQ screen?
ExpansionTileStepperTableBadge
Who sorts the rows of a DataTable?
DataTable automaticallyYour code, inside onSortThe phoneNobody
numeric: true on a DataColumn does what?
Adds a numberRight-aligns the columnHides itSorts it
Score: 0 / 3

Recap: what you learned in Module 27

Card + ListTile

One record, quickly.

Table

Simple fixed grid.

DataTable

Sort and select rows.

Expansion

Hide details until tapped.

Stepper

Guide a multi-step process.

Timeline

Row + dot + line draws it.

Next: Buttons, Inputs and Selection Controls - Every way a user can tap, type and choose
MODULE 28 · PART 2

Buttons, Inputs and Selection Controls

Every way a user can tap, type and choose
You will learn
  • Choose the right button type and style it
  • Use Checkbox, Radio, Switch and their ListTile versions
  • Collect text with TextField and decorations
  • Pick values with Slider, RangeSlider, SegmentedButton and Dropdown
  • Use date pickers, time pickers and Autocomplete
You will build: a login form, a filter panel and a booking form
6 class hours · 10 examples (5 Easy, 3 Medium, 2 Hard)
🔘

Where is this used in real apps?

Every app asks the user to do something: tap Buy, type a phone number, pick a date, switch on notifications. These widgets are the controls of your app.

Buttons

Filled for the main action, outlined or text for the rest.

Selection controls

Checkbox, Radio, Switch, Slider: choose from known options.

Text input

TextField with label, hint, icon and keyboard type.

Book Appointment
📅
Pick date
24 Nov 2026
>
🕑
Pick time
10:30 AM
>
👨
Doctor
Dr. Sinha
>

The button family

Material 3 has five main buttons. Use one filled button per screen for the main action and softer buttons for the rest.

Disabled button: set 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')),
    ])),
  )));
}

Checkbox, Radio, Switch

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.

Remember: these controls do not remember their own value. You keep the value in state and update it in onChanged.
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 and InputDecoration

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).

Always dispose controllers in real apps: 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()));

Sliders, segments, dropdowns and pickers

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.

Picker rule: 2 to 4 choices: SegmentedButton or Radio. 5 to 10: Dropdown. More: a searchable list or Autocomplete.
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()));

Animated explainer: Which button, which emphasis?

Press Next to walk through it step by step, or Auto play.

Animated explainer: Value in state, control shows it

Press Next to walk through it step by step, or Auto play.
EASYReal project: any screen with two or three actionsExample 1 of 10

Which button when?

A typical bottom bar of a cart: a loud Filled button for the main action and an Outlined one for the second.
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'))),
    ]))),
  )));
}
Try it yourself: Add a TextButton "Share" below the row.
Wrap in a Column and add TextButton.
EASYReal project: brand-coloured call-to-actionExample 2 of 10

Styled button

styleFrom sets colours, shape, padding and text style in one place. Use it for the brand button.
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'),
    )),
  )));
}
Try it yourself: Make it green and less round (radius 8).
Colors.green and BorderRadius.circular(8).
EASYReal project: sign-up form: accept termsExample 3 of 10

Consent checkbox

The Pay button stays disabled (onPressed: null) until the box is ticked.
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()));
Try it yourself: Add a second checkbox "Send me offers" that does not block the button.
Add another bool in state.
EASYReal project: app settings screenExample 4 of 10

Settings switches

SwitchListTile pairs a label with a switch. Every row has its own bool in state.
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()));
Try it yourself: Add a Vibration switch.
Add a bool and another SwitchListTile.
EASYReal project: login and sign-up screensExample 5 of 10

Login fields

TextField with OutlineInputBorder, a prefix icon and obscureText for the password.
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())),
    ])),
  )));
}
Try it yourself: Add a "Forgot password?" TextButton below.
Add TextButton in the Column.
MEDIUMReal project: checkout and admission formsExample 6 of 10

Payment method and class dropdown

Radio for 3 payment methods (one choice), DropdownButton for a longer list. Both store their value in state.
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()));
Try it yourself: Add the payment method "Cheque".
Add to the list of methods.
MEDIUMReal project: chart range switch, text formatting barExample 7 of 10

Segmented and toggle buttons

SegmentedButton chooses one option (Day, Week, Month). ToggleButtons are independent on/off buttons (Bold, Italic).
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()));
Try it yourself: Add a fourth segment "Year".
Add a ButtonSegment.
MEDIUMReal project: shopping filters: price, distance, ratingExample 8 of 10

Price filter with RangeSlider

RangeSlider has two handles. divisions make it snap to steps. The filtered list updates live.
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()));
Try it yourself: Show "No items" when the list is empty.
Check shown.isEmpty.
HARDReal project: clinic, salon and coaching class bookingExample 9 of 10

Appointment booking with pickers

showDatePicker and showTimePicker return a Future. await the answer; it is null if the user cancels. The values are stored in state and shown on the button.
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()));
Try it yourself: Show a SnackBar "Booked!" when confirmed.
ScaffoldMessenger.of(context).showSnackBar(...)
HARDReal project: sign-up with city suggestionsExample 10 of 10

Registration form with Autocomplete

Autocomplete suggests cities while typing. All the fields feed one summary. The Register button is enabled only when every field is filled.
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()));
Try it yourself: Add a phone number field and include it in the ready check.
A second controller and phone.text.length == 10.

Quick quiz

3 questions. Click an answer.
How many FilledButtons should one screen usually have?
As many as possibleOne main actionNoneExactly five
How do you disable a button?
visible: falseonPressed: nullenabled: 0color: grey
Which control picks exactly one option from a group?
CheckboxRadioSwitchSlider
Score: 0 / 3

Recap: what you learned in Module 28

Buttons

Filled, tonal, outlined, text, icon.

Selection

Checkbox, Radio, Switch keep value in state.

TextField

Decoration, controller, keyboardType.

Range

Slider, RangeSlider, SegmentedButton.

Pickers

await showDatePicker and showTimePicker.

Autocomplete

Suggest values while typing.

Next: the next part of the course.

Code Lab - write any Dart / Flutter code (Ctrl+Enter to run)