FLUTTER WIDGETS & DESIGN COURSE · BRAINBIT INFOTECH

Part 3

4 modules · 19 class hours · 40 practical examples

Module 29: Navigation Widgets: Scaffold, Drawer, Tabs

Help users move around the app · 5 h

Module 30: Dialogs, Sheets, SnackBars and Progress

Talk to the user and show what is happening · 5 h

Module 31: Gestures, Drag and Drop

Make every pixel respond to touch · 4 h

Module 32: Animation: Implicit, Explicit, Hero

Make the screen move, smoothly · 5 h

MODULE 29 · PART 3

Navigation Widgets: Scaffold, Drawer, Tabs

Help users move around the app
You will learn
  • Understand every part of a Scaffold
  • Build AppBars with actions and menus
  • Add a Drawer and a bottom navigation bar
  • Switch screens with NavigationBar and IndexedStack
  • Use TabBar and TabBarView
You will build: an app shell with drawer, tabs and bottom navigation
5 class hours · 10 examples (5 Easy, 3 Medium, 2 Hard)
🧭

Where is this used in real apps?

Every app needs a way to move between sections: Home, Orders, Profile. Scaffold, Drawer, BottomNavigationBar and TabBar are the standard tools.

Scaffold

The skeleton of a screen: app bar, body, drawer, bottom bar, floating button.

Bottom bar

3 to 5 main sections that users switch often.

Drawer / Tabs

More sections in a side menu, or related lists in tabs.

Swiggy-style Home
🍕
Pizza Corner
Kanke Road
4.3
🍜
Noodle House
Main Road
4.1
🍲
Thali Ghar
Lalpur
4.5
+
🏠
Home
🔍
Search
📦
Orders
👤
Profile

Scaffold anatomy

Scaffold is the frame of a screen. Each slot has a name.

Tip: there is only one Scaffold per screen. Nested Scaffolds are used only for tabs that need their own app bars.
void main() {
  runApp(MaterialApp(home: Scaffold(
    appBar: AppBar(title: const Text('Ranchi Shop'), actions: [IconButton(icon: const Icon(Icons.search), onPressed: () {})]),
    drawer: const Drawer(child: Center(child: Text('Menu'))),
    body: const Center(child: Text('Body')),
    floatingActionButton: FloatingActionButton(onPressed: () {}, child: const Icon(Icons.add)),
    bottomNavigationBar: BottomNavigationBar(items: const [
      BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
      BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
    ]),
  )));
}

Bottom navigation: switching sections

Keep the current index in state. BottomNavigationBar (or the Material 3 NavigationBar) calls onTap with the new index. Show a different body for each index.

Rule: 3 to 5 destinations. More than 5? Use a Drawer for the rest.
class Shell extends StatefulWidget {
  const Shell({super.key});
  @override
  State<Shell> createState() => _ShellState();
}
class _ShellState extends State<Shell> {
  int index = 0;
  final pages = const [Center(child: Text('Home page')), Center(child: Text('Orders page')), Center(child: Text('Profile page'))];
  @override
  Widget build(BuildContext context) => Scaffold(
    body: pages[index],
    bottomNavigationBar: NavigationBar(
      selectedIndex: index,
      onDestinationSelected: (i) => setState(() => index = i),
      destinations: const [
        NavigationDestination(icon: Icon(Icons.home_outlined), selectedIcon: Icon(Icons.home), label: 'Home'),
        NavigationDestination(icon: Icon(Icons.receipt_long_outlined), selectedIcon: Icon(Icons.receipt_long), label: 'Orders'),
        NavigationDestination(icon: Icon(Icons.person_outline), selectedIcon: Icon(Icons.person), label: 'Profile'),
      ],
    ),
  );
}
void main() => runApp(const MaterialApp(home: Shell()));

Drawer: the side menu

Add a Drawer to the Scaffold and the AppBar shows the menu icon automatically. Put a DrawerHeader and ListTile items inside. Tap the menu icon or swipe from the left edge to open it.

Close the drawer after a tap with Navigator.pop(context).
void main() {
  runApp(MaterialApp(home: Scaffold(
    appBar: AppBar(title: const Text('My School')),
    drawer: Drawer(child: ListView(children: [
      const DrawerHeader(decoration: BoxDecoration(color: Colors.indigo), child: Text('DAV School Kanke', style: TextStyle(color: Colors.white, fontSize: 22))),
      ListTile(leading: const Icon(Icons.home), title: const Text('Home'), onTap: () {}),
      ListTile(leading: const Icon(Icons.calendar_month), title: const Text('Timetable'), onTap: () {}),
      ListTile(leading: const Icon(Icons.payments), title: const Text('Fees'), onTap: () {}),
      const Divider(),
      ListTile(leading: const Icon(Icons.logout), title: const Text('Logout'), onTap: () {}),
    ])),
    body: const Center(child: Text('Tap the menu icon')),
  )));
}

TabBar and TabBarView

Tabs show related lists under one screen. DefaultTabController connects a TabBar (the labels) with a TabBarView (the pages). Swiping and tapping stay in sync automatically.

Count carefully: length, the number of Tabs and the number of pages must all be the same.
void main() {
  runApp(const MaterialApp(home: DefaultTabController(
    length: 3,
    child: Scaffold(
      appBar: AppBar(title: Text('Menu'), bottom: TabBar(tabs: [Tab(text: 'Veg'), Tab(text: 'Non-veg'), Tab(text: 'Sweets')])),
      body: TabBarView(children: [
        Center(child: Text('Paneer tikka, Dal fry')),
        Center(child: Text('Chicken curry, Egg roll')),
        Center(child: Text('Rasgulla, Gulab jamun')),
      ]),
    ),
  )));
}

Animated explainer: Parts of a Scaffold

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

Animated explainer: How bottom navigation switches pages

Press Next to walk through it step by step, or Auto play.
EASYReal project: the first screen of any appExample 1 of 10

Screen skeleton

Every slot of Scaffold in one place. Learn the names and you can build any screen layout.
void main() {
  runApp(MaterialApp(home: Scaffold(
    appBar: AppBar(title: const Text('Ranchi Kirana')),
    body: const Center(child: Text('Welcome to Ranchi Kirana', style: TextStyle(fontSize: 20))),
    floatingActionButton: FloatingActionButton(onPressed: () {}, child: const Icon(Icons.add)),
    bottomNavigationBar: BottomNavigationBar(currentIndex: 0, items: const [
      BottomNavigationBarItem(icon: Icon(Icons.store), label: 'Shop'),
      BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: 'Cart'),
    ]),
  )));
}
Try it yourself: Add a third bar item: Profile.
Add BottomNavigationBarItem(Icons.person).
EASYReal project: top bar with search and more menuExample 2 of 10

AppBar actions and popup menu

actions are icons on the right. PopupMenuButton opens a small menu from the three-dot icon.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  String chosen = 'Nothing yet';
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Inbox'), actions: [
      IconButton(icon: const Icon(Icons.search), onPressed: () {}),
      PopupMenuButton<String>(
        onSelected: (v) => setState(() => chosen = v),
        itemBuilder: (c) => const [PopupMenuItem(value: 'Refresh', child: Text('Refresh')), PopupMenuItem(value: 'Settings', child: Text('Settings')), PopupMenuItem(value: 'Help', child: Text('Help'))],
      ),
    ]),
    body: Center(child: Text('Chosen: $chosen', style: const TextStyle(fontSize: 22))),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Add the menu item "About".
Add one more PopupMenuItem.
EASYReal project: side menu in school, bank and shop appsExample 3 of 10

School drawer

Header plus a list of ListTiles. The AppBar menu icon appears by itself once you add a drawer.
void main() {
  runApp(MaterialApp(home: Scaffold(
    appBar: AppBar(title: const Text('Kanke School')),
    drawer: Drawer(child: ListView(children: [
      UserAccountsDrawerHeader(accountName: const Text('Asha Kumari'), accountEmail: const Text('asha@example.com'), currentAccountPicture: const CircleAvatar(child: Text('A'))),
      const ListTile(leading: Icon(Icons.home), title: Text('Home')),
      const ListTile(leading: Icon(Icons.book), title: Text('Homework')),
      const ListTile(leading: Icon(Icons.directions_bus), title: Text('School bus')),
      const ListTile(leading: Icon(Icons.settings), title: Text('Settings')),
    ])),
    body: const Center(child: Text('Open the drawer')),
  )));
}
Try it yourself: Add a Results item.
Add one more ListTile.
EASYReal project: main navigation of most appsExample 4 of 10

Bottom navigation with three pages

The index is state, the body is a list lookup. This is the standard pattern for bottom bars.
class Shell extends StatefulWidget {
  const Shell({super.key});
  @override
  State<Shell> createState() => _ShellState();
}
class _ShellState extends State<Shell> {
  int i = 0;
  @override
  Widget build(BuildContext context) {
    const pages = [Text('Home: offers'), Text('Cart: 2 items'), Text('Profile: Asha')];
    return Scaffold(
      body: Center(child: DefaultTextStyle(style: const TextStyle(fontSize: 24, color: Colors.black), child: pages[i])),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: i, onTap: (v) => setState(() => i = v),
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
          BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: 'Cart'),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
        ],
      ),
    );
  }
}
void main() => runApp(const MaterialApp(home: Shell()));
Try it yourself: Add a Search item.
Add an item and a page.
EASYReal project: modern Android-style bottom barExample 5 of 10

Material 3 NavigationBar

NavigationBar has a pill behind the selected icon, and selectedIcon lets the icon change to a filled version.
class Shell extends StatefulWidget {
  const Shell({super.key});
  @override
  State<Shell> createState() => _ShellState();
}
class _ShellState extends State<Shell> {
  int i = 1;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Text('Tab ${i + 1}', style: const TextStyle(fontSize: 28))),
    bottomNavigationBar: NavigationBar(
      selectedIndex: i, onDestinationSelected: (v) => setState(() => i = v),
      destinations: const [
        NavigationDestination(icon: Icon(Icons.explore_outlined), selectedIcon: Icon(Icons.explore), label: 'Explore'),
        NavigationDestination(icon: Icon(Icons.favorite_border), selectedIcon: Icon(Icons.favorite), label: 'Saved'),
        NavigationDestination(icon: Icon(Icons.person_outline), selectedIcon: Icon(Icons.person), label: 'Me'),
      ],
    ),
  );
}
void main() => runApp(const MaterialApp(home: Shell()));
Try it yourself: Add a fourth destination called Chat.
Add NavigationDestination.
MEDIUMReal project: restaurant and category screensExample 6 of 10

Food menu tabs

DefaultTabController connects the tab labels with the pages. The pages are normal widgets, here lists.
Widget menu(List<List<String>> items) => ListView(children: [for (final i in items) ListTile(title: Text(i[0]), trailing: Text('Rs ${i[1]}'))]);
void main() {
  runApp(MaterialApp(home: DefaultTabController(
    length: 3,
    child: Scaffold(
      appBar: AppBar(title: const Text('Thali Ghar'), bottom: const TabBar(tabs: [Tab(icon: Icon(Icons.eco), text: 'Veg'), Tab(icon: Icon(Icons.set_meal), text: 'Non-veg'), Tab(icon: Icon(Icons.cake), text: 'Sweets')])),
      body: TabBarView(children: [
        menu([['Paneer butter masala', '220'], ['Dal tadka', '140'], ['Aloo gobi', '120']]),
        menu([['Chicken curry', '260'], ['Egg curry', '150'], ['Fish fry', '280']]),
        menu([['Gulab jamun', '60'], ['Rasgulla', '50'], ['Malpua', '70']]),
      ]),
    ),
  )));
}
Try it yourself: Add a fourth tab: Drinks.
Change length to 4 and add a Tab and a page.
MEDIUMReal project: compose and add buttons in Gmail-style appsExample 7 of 10

Extended FAB that shrinks on scroll

A ScrollController flips a bool. FloatingActionButton.extended shows the label at the top and only the icon once the user scrolls.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  final ctl = ScrollController();
  bool big = true;
  @override
  void initState() {
    super.initState();
    ctl.addListener(() {
      final b = ctl.offset < 50;
      if (b != big) setState(() => big = b);
    });
  }
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Mail')),
    body: ListView.builder(controller: ctl, itemCount: 40, itemBuilder: (c, i) => ListTile(leading: const Icon(Icons.mail_outline), title: Text('Message ${i + 1}'))),
    floatingActionButton: FloatingActionButton.extended(
      onPressed: () {}, icon: const Icon(Icons.edit),
      label: big ? const Text('Compose') : const SizedBox.shrink(),
    ),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Change the label to "New mail".
Edit the Text.
MEDIUMReal project: admin and school apps with many sectionsExample 8 of 10

Drawer that changes the page

The drawer ListTiles store the selected index and highlight it with selected: true. Navigator.pop closes the drawer after a tap.
class Home extends StatefulWidget {
  const Home({super.key});
  @override
  State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
  int sel = 0;
  final names = ['Dashboard', 'Students', 'Fees', 'Reports'];
  final icons = [Icons.dashboard, Icons.people, Icons.payments, Icons.bar_chart];
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: Text(names[sel])),
    drawer: Drawer(child: ListView(children: [
      const DrawerHeader(child: Text('School Admin', style: TextStyle(fontSize: 22))),
      for (var i = 0; i < names.length; i++) ListTile(
        leading: Icon(icons[i]), title: Text(names[i]), selected: sel == i,
        onTap: () { setState(() => sel = i); Navigator.pop(context); },
      ),
    ])),
    body: Center(child: Text('${names[sel]} page', style: const TextStyle(fontSize: 26))),
  );
}
void main() => runApp(const MaterialApp(home: Home()));
Try it yourself: Add the section Attendance.
Add to names and icons.
HARDReal project: Instagram or Amazon style apps where each tab keeps its placeExample 9 of 10

App shell with IndexedStack

A plain body: pages[i] rebuilds the page and loses its counter. IndexedStack keeps all pages alive and only shows one, so each tab remembers its state.
class Counter extends StatefulWidget {
  final String name;
  const Counter(this.name, {super.key});
  @override
  State<Counter> createState() => _CounterState();
}
class _CounterState extends State<Counter> {
  int n = 0;
  @override
  Widget build(BuildContext context) => Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
    Text('${widget.name}: $n', style: const TextStyle(fontSize: 26)),
    FilledButton(onPressed: () => setState(() => n++), child: const Text('Add')),
  ]));
}
class Shell extends StatefulWidget {
  const Shell({super.key});
  @override
  State<Shell> createState() => _ShellState();
}
class _ShellState extends State<Shell> {
  int i = 0;
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('IndexedStack demo')),
    body: IndexedStack(index: i, children: const [Counter('Home'), Counter('Orders'), Counter('Profile')]),
    bottomNavigationBar: NavigationBar(
      selectedIndex: i, onDestinationSelected: (v) => setState(() => i = v),
      destinations: const [
        NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
        NavigationDestination(icon: Icon(Icons.receipt), label: 'Orders'),
        NavigationDestination(icon: Icon(Icons.person), label: 'Profile'),
      ],
    ),
  );
}
void main() => runApp(const MaterialApp(home: Shell()));
Try it yourself: Press Add on Home 3 times, switch tab, come back: is it still 3? Now replace IndexedStack with a plain list lookup.
children[i] instead of IndexedStack.
HARDReal project: search icon that turns the title into a text boxExample 10 of 10

Search toggle in the AppBar

A bool decides the AppBar title: a normal title, or a TextField. Typing filters the list. The close icon clears and returns to the title.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  bool searching = false;
  String q = '';
  final all = ['Ranchi', 'Patna', 'Gaya', 'Dhanbad', 'Bokaro', 'Deoghar', 'Muzaffarpur', 'Purnia'];
  @override
  Widget build(BuildContext context) {
    final list = all.where((e) => e.toLowerCase().contains(q.toLowerCase())).toList();
    return Scaffold(
      appBar: AppBar(
        title: searching
            ? TextField(autofocus: true, decoration: const InputDecoration(hintText: 'Search city', border: InputBorder.none), onChanged: (v) => setState(() => q = v))
            : const Text('Cities'),
        actions: [IconButton(
          icon: Icon(searching ? Icons.close : Icons.search),
          onPressed: () => setState(() { searching = !searching; q = ''; }),
        )],
      ),
      body: ListView(children: [for (final c in list) ListTile(title: Text(c))]),
    );
  }
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Show "No result" when the list is empty.
if (list.isEmpty) Center(child: Text(...)).

Quick quiz

3 questions. Click an answer.
Where do you keep the selected bottom-bar tab?
In state (an int index)In the AppBarIn pubspec.yamlIt is automatic
What keeps every tab page alive when switching?
ColumnIndexedStackWrapPadding
Which widget connects TabBar and TabBarView?
DefaultTabControllerScaffoldDrawerStack
Score: 0 / 3

Recap: what you learned in Module 29

Scaffold

appBar, body, drawer, FAB, bottom bar.

Bottom bar

index in state, 3 to 5 sections.

Drawer

Side menu; pop it after a tap.

Tabs

DefaultTabController + TabBar + TabBarView.

IndexedStack

Keeps tab state alive.

AppBar tricks

Actions, popup menu, search toggle.

Next: Dialogs, Sheets, SnackBars and Progress - Talk to the user and show what is happening
MODULE 30 · PART 3

Dialogs, Sheets, SnackBars and Progress

Talk to the user and show what is happening
You will learn
  • Ask questions with AlertDialog and showDialog
  • Give quick feedback with SnackBar and an Undo action
  • Offer choices in a bottom sheet
  • Show progress with CircularProgressIndicator and LinearProgressIndicator
  • Build skeleton loaders while data loads
You will build: a delete-with-undo flow, a share sheet and a loading skeleton
5 class hours · 10 examples (5 Easy, 3 Medium, 2 Hard)
💬

Where is this used in real apps?

When the user deletes an order, pays a bill or waits for a server, the app must answer: "Are you sure?", "Deleted. Undo?", "Loading...". These small messages make an app feel trustworthy.

Dialog

Stops everything and asks. Use for confirmations.

SnackBar

A short message at the bottom that disappears. Can have an action.

Progress

Spinners and bars that say: please wait.

Orders
📦
Order #1042
Delete this order?
Yes
📦
Order #1043
Shipped
📦
Order #1044
Packed

AlertDialog and showDialog

showDialog puts a dialog on top of the screen and returns a Future. When the user taps a button, you call Navigator.pop(context, value) and that value comes back to your await.

Tip: use a dialog only when the user must decide. For simple information a SnackBar is less annoying.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  String result = 'No answer yet';
  Future<void> ask() async {
    final ok = await showDialog<bool>(
      context: context,
      builder: (ctx) => AlertDialog(
        title: const Text('Delete order?'),
        content: const Text('Order #1042 will be removed.'),
        actions: [
          TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('Cancel')),
          FilledButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('Delete')),
        ],
      ),
    );
    setState(() => result = ok == true ? 'Deleted' : 'Cancelled');
  }
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
      FilledButton(onPressed: ask, child: const Text('Delete order')),
      const SizedBox(height: 16),
      Text(result),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

SnackBar and Undo

Get the messenger with ScaffoldMessenger.of(context) and call showSnackBar. A SnackBarAction adds a button such as UNDO. A snack bar disappears after a few seconds.

Undo pattern: delete from the list first, show the snack bar, and put the item back if the user taps UNDO.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  final items = ['Dhuska', 'Litti', 'Thekua'];
  @override
  Widget build(BuildContext context) => Scaffold(
    body: ListView(children: [
      for (final s in List.of(items)) ListTile(
        title: Text(s),
        trailing: IconButton(icon: const Icon(Icons.delete), onPressed: () {
          final idx = items.indexOf(s);
          setState(() => items.remove(s));
          ScaffoldMessenger.of(context).showSnackBar(SnackBar(
            content: Text('$s deleted'),
            action: SnackBarAction(label: 'UNDO', onPressed: () => setState(() => items.insert(idx, s))),
          ));
        }),
      ),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

Bottom sheet

showModalBottomSheet slides a panel up from the bottom. It is perfect for share menus, filters and quick choices, and it is easier to reach with a thumb than a dialog.

Pick the right one: Dialog = must decide. Bottom sheet = choose an option. SnackBar = just informing.
class Page extends StatelessWidget {
  const Page({super.key});
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: FilledButton(
      onPressed: () => showModalBottomSheet(
        context: context,
        builder: (ctx) => Column(mainAxisSize: MainAxisSize.min, children: [
          const ListTile(title: Text('Share via', style: TextStyle(fontWeight: FontWeight.bold))),
          ListTile(leading: const Icon(Icons.message), title: const Text('WhatsApp'), onTap: () => Navigator.pop(ctx)),
          ListTile(leading: const Icon(Icons.mail), title: const Text('Email'), onTap: () => Navigator.pop(ctx)),
          ListTile(leading: const Icon(Icons.copy), title: const Text('Copy link'), onTap: () => Navigator.pop(ctx)),
        ]),
      ),
      child: const Text('Share'),
    )),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

Progress indicators

Without a value the indicator spins or slides forever (indeterminate). With value from 0.0 to 1.0 it shows real progress (determinate).

Honest note: in the slide engine the spinner is a simple CSS animation; on a real phone it is drawn by Flutter with the Material motion curve.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  double p = 0.35;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Padding(padding: const EdgeInsets.all(24), child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
      const CircularProgressIndicator(),
      const SizedBox(height: 24),
      LinearProgressIndicator(value: p),
      const SizedBox(height: 8),
      Text('Downloading ${(p * 100).round()}%'),
      Slider(value: p, onChanged: (v) => setState(() => p = v)),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

Animated explainer: How await showDialog works

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

Animated explainer: Which feedback widget?

Press Next to walk through it step by step, or Auto play.
EASYReal project: deleting orders, files, accountsExample 1 of 10

Confirm before delete

A dialog with Cancel and Delete. The result (true or false) decides what happens next.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  String status = 'Order #1042 is active';
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
      Text(status, style: const TextStyle(fontSize: 18)),
      const SizedBox(height: 16),
      ElevatedButton(onPressed: () async {
        final ok = await showDialog<bool>(context: context, builder: (c) => AlertDialog(
          title: const Text('Cancel order?'),
          content: const Text('You cannot undo this.'),
          actions: [TextButton(onPressed: () => Navigator.pop(c, false), child: const Text('No')), TextButton(onPressed: () => Navigator.pop(c, true), child: const Text('Yes, cancel'))],
        ));
        if (ok == true) setState(() => status = 'Order #1042 cancelled');
      }, child: const Text('Cancel order')),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Change the dialog title and button texts to Hindi-style words like "Haan" and "Nahi".
Edit the strings.
EASYReal project: "Item added to cart" messagesExample 2 of 10

Simple SnackBar

ScaffoldMessenger.of(context).showSnackBar shows a message at the bottom for a few seconds.
void main() {
  runApp(MaterialApp(home: Builder(builder: (context) => Scaffold(
    body: Center(child: FilledButton(
      onPressed: () => ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Added to cart: Atta 5 kg'))),
      child: const Text('Add to cart'),
    )),
  ))));
}
Try it yourself: Change the duration to 5 seconds.
duration: Duration(seconds: 5).
EASYReal project: email, notes, to-do appsExample 3 of 10

Delete with Undo

A SnackBarAction gives the user a few seconds to change their mind. Much friendlier than a confirmation dialog for small things.
class Todo extends StatefulWidget {
  const Todo({super.key});
  @override
  State<Todo> createState() => _TodoState();
}
class _TodoState extends State<Todo> {
  final tasks = ['Buy vegetables', 'Pay electricity bill', 'Call Ravi'];
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Tasks')),
    body: ListView(children: [
      for (final t in List.of(tasks)) ListTile(
        title: Text(t),
        trailing: IconButton(icon: const Icon(Icons.check), onPressed: () {
          final i = tasks.indexOf(t);
          setState(() => tasks.remove(t));
          ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Done: $t'), action: SnackBarAction(label: 'UNDO', onPressed: () => setState(() => tasks.insert(i, t)))));
        }),
      ),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Todo()));
Try it yourself: Add a fourth task.
Add a string to tasks.
EASYReal project: share, sort and filter menusExample 4 of 10

Share bottom sheet

showModalBottomSheet with a Column of ListTiles. It is easy to reach with the thumb and closes when the user taps outside.
void main() {
  runApp(MaterialApp(home: Builder(builder: (context) => Scaffold(
    body: Center(child: FilledButton.icon(
      icon: const Icon(Icons.share), label: const Text('Share offer'),
      onPressed: () => showModalBottomSheet(context: context, builder: (c) => Padding(padding: const EdgeInsets.all(16), child: Column(mainAxisSize: MainAxisSize.min, children: [
        const Text('Share this offer', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
        const SizedBox(height: 8),
        ListTile(leading: const Icon(Icons.chat), title: const Text('WhatsApp'), onTap: () => Navigator.pop(c)),
        ListTile(leading: const Icon(Icons.sms), title: const Text('SMS'), onTap: () => Navigator.pop(c)),
      ]))),
    )),
  ))));
}
Try it yourself: Add an Email option.
Add another ListTile.
EASYReal project: file upload, course progress, step progressExample 5 of 10

Progress bars

Pass a value between 0 and 1 to get a determinate bar. The same widget works for the spinner without a value.
void main() {
  runApp(const MaterialApp(home: Scaffold(
    body: Padding(padding: EdgeInsets.all(24), child: Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [
      Text('Flutter course 62%'),
      SizedBox(height: 6),
      LinearProgressIndicator(value: 0.62, minHeight: 10),
      SizedBox(height: 28),
      Text('Uploading photo...'),
      SizedBox(height: 6),
      LinearProgressIndicator(),
      SizedBox(height: 28),
      Center(child: CircularProgressIndicator(value: 0.75, strokeWidth: 8)),
    ])),
  )));
}
Try it yourself: Change the course progress to 90%.
value: 0.9.
MEDIUMReal project: submit, pay and save buttonsExample 6 of 10

Button that shows a spinner while saving

A loading bool in state swaps the label for a small spinner and disables the button. When the Future finishes, a SnackBar confirms.
class Save extends StatefulWidget {
  const Save({super.key});
  @override
  State<Save> createState() => _SaveState();
}
class _SaveState extends State<Save> {
  bool loading = false;
  Future<void> save() async {
    setState(() => loading = true);
    await Future.delayed(const Duration(seconds: 2));
    if (!mounted) return;
    setState(() => loading = false);
    ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Profile saved')));
  }
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: FilledButton(
      onPressed: loading ? null : save,
      child: loading ? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white)) : const Text('Save profile'),
    )),
  );
}
void main() => runApp(const MaterialApp(home: Save()));
Try it yourself: Show "Saving..." text next to the spinner.
Use a Row with the spinner and a Text.
MEDIUMReal project: rename, add item, enter couponExample 7 of 10

Dialog with a text field

The dialog holds a TextEditingController. When the user presses Add, the text is returned with Navigator.pop, then added to the list.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  final items = ['Rice', 'Dal'];
  Future<void> add() async {
    final c = TextEditingController();
    final name = await showDialog<String>(context: context, builder: (ctx) => AlertDialog(
      title: const Text('Add item'),
      content: TextField(controller: c, autofocus: true, decoration: const InputDecoration(hintText: 'Item name')),
      actions: [TextButton(onPressed: () => Navigator.pop(ctx), child: const Text('Cancel')), FilledButton(onPressed: () => Navigator.pop(ctx, c.text), child: const Text('Add'))],
    ));
    if (name != null && name.isNotEmpty) setState(() => items.add(name));
  }
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Grocery list')),
    body: ListView(children: [for (final i in items) ListTile(title: Text(i))]),
    floatingActionButton: FloatingActionButton(onPressed: add, child: const Icon(Icons.add)),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Show a SnackBar after adding.
Call ScaffoldMessenger after setState.
MEDIUMReal project: language, theme and region settingsExample 8 of 10

Language chooser with SimpleDialog

SimpleDialog with SimpleDialogOption rows. Each option pops its own value. A Tooltip explains the icon on long press.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  String lang = 'English';
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Settings'), actions: [
      Tooltip(message: 'Change language', child: IconButton(icon: const Icon(Icons.language), onPressed: () async {
        final l = await showDialog<String>(context: context, builder: (c) => SimpleDialog(title: const Text('Choose language'), children: [
          for (final x in ['English', 'Hindi', 'Santhali', 'Bhojpuri']) SimpleDialogOption(onPressed: () => Navigator.pop(c, x), child: Text(x)),
        ]));
        if (l != null) setState(() => lang = l);
      })),
    ]),
    body: Center(child: Text('Language: $lang', style: const TextStyle(fontSize: 24))),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Add Nagpuri to the languages.
Add it to the list.
HARDReal project: feeds and product lists while data loadsExample 9 of 10

Skeleton loader

Grey placeholder boxes pulse while loading, then the real content replaces them. Users see the layout immediately, so the app feels faster than a lone spinner.
import 'dart:async';

class Feed extends StatefulWidget {
  const Feed({super.key});
  @override
  State<Feed> createState() => _FeedState();
}
class _FeedState extends State<Feed> {
  bool loading = true, pulse = false;
  Timer? t;
  @override
  void initState() {
    super.initState();
    t = Timer.periodic(const Duration(milliseconds: 700), (x) => setState(() => pulse = !pulse));
    Future.delayed(const Duration(seconds: 3), () { if (mounted) setState(() => loading = false); });
  }
  @override
  void dispose() { t?.cancel(); super.dispose(); }
  Widget box(double w, double h) => AnimatedOpacity(
    duration: const Duration(milliseconds: 600), opacity: pulse ? 0.4 : 1,
    child: Container(width: w, height: h, decoration: BoxDecoration(color: Colors.grey.shade300, borderRadius: BorderRadius.circular(6))),
  );
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('News')),
    body: ListView(padding: const EdgeInsets.all(16), children: [
      for (var i = 0; i < 4; i++) Padding(padding: const EdgeInsets.only(bottom: 18), child: loading
        ? Row(children: [box(64, 64), const SizedBox(width: 12), Column(crossAxisAlignment: CrossAxisAlignment.start, children: [box(180, 14), const SizedBox(height: 8), box(120, 12)])])
        : Row(children: [Container(width: 64, height: 64, color: Colors.teal.shade100, child: const Icon(Icons.article)), const SizedBox(width: 12), Text('Ranchi news headline ${i + 1}')])),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Feed()));
Try it yourself: Make loading last 5 seconds.
Change the Duration in Future.delayed.
HARDReal project: checkout and booking flowsExample 10 of 10

Payment flow: confirm, wait, success

Three feedback widgets in a row: an AlertDialog to confirm, a progress dialog that cannot be dismissed while waiting, and a bottom sheet showing success. This is a real payment flow.
class Pay extends StatefulWidget {
  const Pay({super.key});
  @override
  State<Pay> createState() => _PayState();
}
class _PayState extends State<Pay> {
  Future<void> pay() async {
    final ok = await showDialog<bool>(context: context, builder: (c) => AlertDialog(
      title: const Text('Pay Rs 1,240?'), content: const Text('Via UPI to Kanke Road Kirana'),
      actions: [TextButton(onPressed: () => Navigator.pop(c, false), child: const Text('Cancel')), FilledButton(onPressed: () => Navigator.pop(c, true), child: const Text('Pay'))],
    ));
    if (ok != true) return;
    showDialog(context: context, barrierDismissible: false, builder: (c) => const AlertDialog(content: Row(children: [CircularProgressIndicator(), SizedBox(width: 20), Text('Processing...')])));
    await Future.delayed(const Duration(seconds: 2));
    if (!mounted) return;
    Navigator.pop(context);
    showModalBottomSheet(context: context, builder: (c) => const Padding(padding: EdgeInsets.all(32), child: Column(mainAxisSize: MainAxisSize.min, children: [
      Icon(Icons.check_circle, color: Colors.green, size: 64),
      SizedBox(height: 12),
      Text('Payment successful', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
      Text('Transaction ID 8841 2207'),
    ])));
  }
  @override
  Widget build(BuildContext context) => Scaffold(body: Center(child: FilledButton(onPressed: pay, child: const Text('Pay Rs 1,240'))));
}
void main() => runApp(const MaterialApp(home: Pay()));
Try it yourself: Add an error path: if the amount is above Rs 5,000 show a SnackBar "Limit exceeded".
Check an amount variable before showing the dialogs.

Quick quiz

3 questions. Click an answer.
What does showDialog return?
A Future with the value passed to Navigator.popNothingA WidgetA String always
Which is best for a quick Undo?
AlertDialogSnackBar with actionDrawerTooltip
A LinearProgressIndicator without value shows:
0%100%An endless moving barNothing
Score: 0 / 3

Recap: what you learned in Module 30

AlertDialog

Confirm and decide; await the result.

SnackBar

Short messages with Undo.

BottomSheet

Choose an option near the thumb.

Progress

Determinate with value, else endless.

Loading button

Bool + spinner + disabled button.

Skeleton

Placeholders feel faster than spinners.

Next: Gestures, Drag and Drop - Make every pixel respond to touch
MODULE 31 · PART 3

Gestures, Drag and Drop

Make every pixel respond to touch
You will learn
  • Detect taps, double taps and long presses with GestureDetector
  • Show ripple feedback with InkWell
  • Move things with Draggable and DragTarget
  • Swipe to delete with Dismissible
  • Reorder items with ReorderableListView
You will build: a swipe-to-delete inbox, a drag-and-drop task board and a sortable list
4 class hours · 10 examples (5 Easy, 3 Medium, 2 Hard)
👆

Where is this used in real apps?

Swipe an email away, hold and drag a task to another column, long-press a photo to select it. All of these are gestures. Flutter turns raw touch into friendly events.

GestureDetector

Wrap any widget and listen to tap, double tap, long press and drag.

InkWell

Same as tap, but with the Material ripple effect.

Drag and drop

Draggable, DragTarget, Dismissible and ReorderableListView.

Inbox
✉
Rahul Singh
Class timing changed
9:10
✉
Ranchi Library
Book due tomorrow
8:40
✉
Kanke Dairy
Milk bill for October
Mon

GestureDetector

Wrap any widget in GestureDetector and give it callbacks: onTap, onDoubleTap, onLongPress. It has no visual effect of its own.

Tip: a GestureDetector over an empty area needs behavior: HitTestBehavior.opaque to catch touches.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  String msg = 'Touch the box';
  Color c = Colors.indigo;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
      GestureDetector(
        onTap: () => setState(() => msg = 'Tap'),
        onDoubleTap: () => setState(() { msg = 'Double tap'; c = Colors.orange; }),
        onLongPress: () => setState(() { msg = 'Long press'; c = Colors.green; }),
        child: Container(width: 160, height: 160, color: c, alignment: Alignment.center, child: const Text('Me', style: TextStyle(color: Colors.white, fontSize: 28))),
      ),
      const SizedBox(height: 20),
      Text(msg, style: const TextStyle(fontSize: 20)),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

InkWell: tap with ripple

InkWell gives the Material splash. It must sit on a Material (Card, Scaffold or Material widget) and paints the ripple on that surface.

Rule of thumb: use InkWell or a Button for things the user taps. Use GestureDetector for custom gestures.
void main() {
  runApp(MaterialApp(home: Scaffold(
    body: Center(child: Card(child: InkWell(
      onTap: () {},
      borderRadius: BorderRadius.circular(12),
      child: const Padding(padding: EdgeInsets.all(28), child: Text('Tap me for ripple', style: TextStyle(fontSize: 20))),
    ))),
  )));
}

Dismissible: swipe to delete

Wrap each list item in Dismissible with a unique key. Swiping removes it. In onDismissed you must remove the item from your list too.

Common error: forgetting to remove the item from the list. Flutter then complains that a dismissed widget is still in the tree.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  final mails = ['Class timing changed', 'Library book due', 'Milk bill', 'Exam form'];
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Inbox')),
    body: ListView(children: [
      for (final m in mails) Dismissible(
        key: ValueKey(m),
        background: Container(color: Colors.red, alignment: Alignment.centerRight, padding: const EdgeInsets.only(right: 20), child: const Icon(Icons.delete, color: Colors.white)),
        onDismissed: (d) => setState(() => mails.remove(m)),
        child: ListTile(leading: const Icon(Icons.mail), title: Text(m)),
      ),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

Draggable and DragTarget

A Draggable carries data. A DragTarget accepts it with onAcceptWithDetails (or onAccept). While dragging, feedback is what the finger holds.

Generics: Draggable<String> and DragTarget<String> must use the same type, otherwise the drop is refused.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  String where = 'Drag the ball into the box';
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
      Draggable<String>(
        data: 'ball',
        feedback: const CircleAvatar(radius: 30, backgroundColor: Colors.orange),
        childWhenDragging: const CircleAvatar(radius: 30, backgroundColor: Colors.grey),
        child: const CircleAvatar(radius: 30, backgroundColor: Colors.orange),
      ),
      DragTarget<String>(
        onAcceptWithDetails: (d) => setState(() => where = 'Dropped: ${d.data}'),
        builder: (c, cand, rej) => Container(width: 160, height: 120, color: cand.isNotEmpty ? Colors.green.shade200 : Colors.blue.shade100, alignment: Alignment.center, child: const Text('Drop here')),
      ),
      Text(where),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

Animated explainer: From finger to callback

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

Animated explainer: Drag and drop life cycle

Press Next to walk through it step by step, or Auto play.
EASYReal project: like button, quantity buttonsExample 1 of 10

Tap counter

GestureDetector.onTap on a Container. Every tap calls setState and the number changes.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  int likes = 0;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: GestureDetector(
      onTap: () => setState(() => likes++),
      child: Container(padding: const EdgeInsets.all(24), decoration: BoxDecoration(color: Colors.pink.shade50, borderRadius: BorderRadius.circular(16)), child: Column(mainAxisSize: MainAxisSize.min, children: [
        const Icon(Icons.favorite, color: Colors.pink, size: 48),
        Text('$likes likes', style: const TextStyle(fontSize: 22)),
      ])),
    )),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Make double tap add 10 likes.
Add onDoubleTap.
EASYReal project: gallery and chat selectionExample 2 of 10

Long press to select

onLongPress toggles a selected state. The border and tick show the selection.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  final sel = <int>{};
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: Text(sel.isEmpty ? 'Photos' : '${sel.length} selected')),
    body: GridView.count(crossAxisCount: 3, mainAxisSpacing: 6, crossAxisSpacing: 6, padding: const EdgeInsets.all(6), children: [
      for (var i = 0; i < 9; i++) GestureDetector(
        onLongPress: () => setState(() => sel.contains(i) ? sel.remove(i) : sel.add(i)),
        onTap: () { if (sel.isNotEmpty) setState(() => sel.contains(i) ? sel.remove(i) : sel.add(i)); },
        child: Container(color: Colors.primaries[i * 2 % 18].shade200, child: sel.contains(i) ? const Icon(Icons.check_circle, color: Colors.white) : null),
      ),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Show a Delete button in the AppBar when something is selected.
actions: [if (sel.isNotEmpty) IconButton(...)].
EASYReal project: tappable cards in listsExample 3 of 10

InkWell card

A Card with an InkWell inside gives the ripple. Without Card or Material the ripple would be invisible.
void main() {
  runApp(MaterialApp(home: Scaffold(
    appBar: AppBar(title: const Text('Courses')),
    body: ListView(padding: const EdgeInsets.all(12), children: [
      for (final c in ['Flutter', 'Python', 'Excel']) Card(child: InkWell(
        onTap: () {},
        child: Padding(padding: const EdgeInsets.all(20), child: Row(children: [
          const Icon(Icons.school), const SizedBox(width: 16), Text(c, style: const TextStyle(fontSize: 20)), const Spacer(), const Icon(Icons.chevron_right),
        ])),
      )),
    ]),
  )));
}
Try it yourself: Change the splash color with splashColor: Colors.orange.
It is a parameter of InkWell.
EASYReal project: email, notificationsExample 4 of 10

Swipe to delete

Dismissible with a red background and a key. onDismissed removes the item from the list.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  final list = ['Dhurwa bus pass', 'Morabadi gym fee', 'Lalpur rent', 'Doranda tuition'];
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Reminders')),
    body: ListView(children: [
      for (final x in list) Dismissible(
        key: ValueKey(x),
        background: Container(color: Colors.red.shade400),
        onDismissed: (_) => setState(() => list.remove(x)),
        child: ListTile(title: Text(x)),
      ),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Add a snackbar saying "Removed".
ScaffoldMessenger in onDismissed.
EASYReal project: basis of every drag-and-drop UIExample 5 of 10

Draggable ball

A Draggable with a feedback widget. The original turns grey while you drag.
void main() {
  runApp(const MaterialApp(home: Scaffold(
    body: Center(child: Draggable<int>(
      data: 1,
      feedback: CircleAvatar(radius: 34, backgroundColor: Colors.deepOrange),
      childWhenDragging: CircleAvatar(radius: 34, backgroundColor: Colors.grey),
      child: CircleAvatar(radius: 34, backgroundColor: Colors.deepOrange, child: Text('Drag', style: TextStyle(color: Colors.white))),
    )),
  )));
}
Try it yourself: Make the feedback bigger than the original.
Change the radius of feedback only.
MEDIUMReal project: archive or delete in mail appsExample 6 of 10

Swipe with two directions

background shows for swipe right, secondaryBackground for swipe left. direction in onDismissed tells which side.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  final list = ['Fee reminder', 'Result declared', 'Holiday notice'];
  String last = 'Swipe an item';
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: Text(last)),
    body: ListView(children: [
      for (final x in List.of(list)) Dismissible(
        key: ValueKey(x),
        background: Container(color: Colors.green, alignment: Alignment.centerLeft, padding: const EdgeInsets.only(left: 20), child: const Icon(Icons.archive, color: Colors.white)),
        secondaryBackground: Container(color: Colors.red, alignment: Alignment.centerRight, padding: const EdgeInsets.only(right: 20), child: const Icon(Icons.delete, color: Colors.white)),
        onDismissed: (dir) => setState(() { list.remove(x); last = dir == DismissDirection.startToEnd ? 'Archived $x' : 'Deleted $x'; }),
        child: ListTile(title: Text(x)),
      ),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Ask for confirmation before delete using confirmDismiss.
confirmDismiss returns Future.
MEDIUMReal project: playlists, priorities, favourite listsExample 7 of 10

Reorder a list

ReorderableListView needs a key on every child and an onReorder that moves the item. Remember: when moving down, the new index is one too large.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  final items = ['Ranchi Lake', 'Rock Garden', 'Jagannath Temple', 'Hundru Falls'];
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Trip order')),
    body: ReorderableListView(
      onReorder: (o, n) => setState(() {
        if (n > o) n -= 1;
        final it = items.removeAt(o);
        items.insert(n, it);
      }),
      children: [for (final i in items) ListTile(key: ValueKey(i), title: Text(i), leading: const Icon(Icons.place))],
    ),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Show the number of each stop (1, 2, 3...).
Use items.indexOf(i) + 1.
MEDIUMReal project: drag to delete, drag to categoriseExample 8 of 10

Drag into a bin

A DragTarget bin turns red while an item hovers. Dropping removes it from the list.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  final files = ['notes.pdf', 'fee.jpg', 'plan.xlsx'];
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Files')),
    body: Column(children: [
      Expanded(child: ListView(children: [
        for (final f in files) Padding(padding: const EdgeInsets.all(8), child: Draggable<String>(
          data: f,
          feedback: Material(child: Chip(label: Text(f))),
          childWhenDragging: Opacity(opacity: 0.3, child: Chip(label: Text(f))),
          child: Chip(avatar: const Icon(Icons.insert_drive_file), label: Text(f)),
        )),
      ])),
      DragTarget<String>(
        onAcceptWithDetails: (d) => setState(() => files.remove(d.data)),
        builder: (c, cand, rej) => Container(height: 100, width: double.infinity, color: cand.isNotEmpty ? Colors.red.shade300 : Colors.red.shade50, alignment: Alignment.center, child: const Icon(Icons.delete, size: 40)),
      ),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Count how many files were deleted and show it in the AppBar.
Keep an int deleted in State.
HARDReal project: Trello, Jira and task appsExample 9 of 10

Kanban board (To do / Done)

Two DragTarget columns. A card dragged from one column is removed from its list and added to the other. This is the core of a real task board.
class Board extends StatefulWidget {
  const Board({super.key});
  @override
  State<Board> createState() => _BoardState();
}
class _BoardState extends State<Board> {
  final todo = ['Prepare invoice', 'Call supplier', 'Update stock'];
  final done = <String>['Open shop'];
  Widget column(String title, List<String> mine, List<String> other, Color c) => Expanded(child: DragTarget<String>(
    onAcceptWithDetails: (d) => setState(() { other.remove(d.data); if (!mine.contains(d.data)) mine.add(d.data); }),
    builder: (ctx, cand, rej) => Container(margin: const EdgeInsets.all(6), padding: const EdgeInsets.all(8), decoration: BoxDecoration(color: cand.isNotEmpty ? c.withOpacity(0.35) : c.withOpacity(0.12), borderRadius: BorderRadius.circular(12)), child: Column(children: [
      Text(title, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
      const SizedBox(height: 8),
      for (final t in mine) Padding(padding: const EdgeInsets.only(bottom: 6), child: Draggable<String>(
        data: t,
        feedback: Material(child: Card(child: Padding(padding: const EdgeInsets.all(10), child: Text(t)))),
        childWhenDragging: Opacity(opacity: 0.3, child: Card(child: Padding(padding: const EdgeInsets.all(10), child: Text(t)))),
        child: Card(child: SizedBox(width: double.infinity, child: Padding(padding: const EdgeInsets.all(10), child: Text(t)))),
      )),
    ])),
  ));
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Shop tasks')),
    body: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [column('To do', todo, done, Colors.orange), column('Done', done, todo, Colors.green)]),
  );
}
void main() => runApp(const MaterialApp(home: Board()));
Try it yourself: Add a third column "Doing".
Another list and another column call; each other-list removal must be handled.
HARDReal project: dating, flashcard and shortlisting appsExample 10 of 10

Swipe card stack (Yes / No)

A card follows the finger with onPanUpdate using Transform.translate and rotates a little. If it is dragged far enough it flies away, otherwise it springs back.
class Swipe extends StatefulWidget {
  const Swipe({super.key});
  @override
  State<Swipe> createState() => _SwipeState();
}
class _SwipeState extends State<Swipe> {
  final names = ['Anita Kumari', 'Vikash Oraon', 'Pooja Sahu'];
  double dx = 0;
  String last = 'Swipe left or right';
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: Text(last)),
    body: Center(child: names.isEmpty ? const Text('No more profiles') : GestureDetector(
      onPanUpdate: (d) => setState(() => dx += d.delta.dx),
      onPanEnd: (d) => setState(() {
        if (dx.abs() > 100) { last = (dx > 0 ? 'Shortlisted ' : 'Skipped ') + names.first; names.removeAt(0); }
        dx = 0;
      }),
      child: Transform.translate(offset: Offset(dx, 0), child: Transform.rotate(angle: dx / 1000, child: Card(elevation: 6, child: SizedBox(width: 240, height: 300, child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
        const CircleAvatar(radius: 50, child: Icon(Icons.person, size: 50)),
        const SizedBox(height: 16),
        Text(names.first, style: const TextStyle(fontSize: 22)),
        const Text('Candidate - Ranchi'),
      ]))))),
    )),
  );
}
void main() => runApp(const MaterialApp(home: Swipe()));
Try it yourself: Show a green "YES" or red "NO" label while the card is moving.
Check dx > 40 or dx < -40 in build.

Quick quiz

3 questions. Click an answer.
What must every Dismissible have?
A unique keyAn iconA ScaffoldA color
Which widget gives a tap ripple?
GestureDetectorInkWellContainerPadding
A DragTarget accepts data from a Draggable of:
Any typeThe same generic typeOnly StringOnly int
Score: 0 / 3

Recap: what you learned in Module 31

GestureDetector

Tap, double tap, long press, pan.

InkWell

Tap with Material ripple.

Dismissible

Swipe away; key + remove from list.

Draggable

Carries data and feedback.

DragTarget

Accepts a drop and highlights.

Reorderable

onReorder moves the item; adjust the index.

Next: Animation: Implicit, Explicit, Hero - Make the screen move, smoothly
MODULE 32 · PART 3

Animation: Implicit, Explicit, Hero

Make the screen move, smoothly
You will learn
  • Use implicit animations: AnimatedContainer, AnimatedOpacity, AnimatedSwitcher
  • Choose a Duration and a Curve
  • Drive explicit animations with AnimationController
  • Use FadeTransition, ScaleTransition and RotationTransition
  • Fly a picture between screens with Hero
You will build: an animated like button, a pulsing loader, a Hero photo page and a staggered menu
5 class hours · 10 examples (5 Easy, 3 Medium, 2 Hard)
✨

Where is this used in real apps?

A heart that pops when liked, a menu that slides in, a button that grows, a photo that flies to full screen. Small motion tells users what just happened.

Implicit

Change a value and Flutter animates to it. Easiest. Use first.

Explicit

You hold an AnimationController. More power: repeat, reverse, sync.

Hero

One widget flies from one screen to the next.

Likes
❤
Tea stall photo
24 likes
❤
Morabadi sunset
58 likes
❤
Ranchi Lake
103 likes

Implicit animation: AnimatedContainer

Replace Container with AnimatedContainer, add a duration. Now whenever width, color or radius changes inside setState, Flutter animates between old and new values.

Tip: you never write the in-between frames. You only say where to end up and how long it takes.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  bool big = false;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
      AnimatedContainer(
        duration: const Duration(milliseconds: 600),
        curve: Curves.easeInOut,
        width: big ? 220 : 100, height: big ? 220 : 100,
        decoration: BoxDecoration(color: big ? Colors.teal : Colors.orange, borderRadius: BorderRadius.circular(big ? 110 : 12)),
      ),
      const SizedBox(height: 24),
      FilledButton(onPressed: () => setState(() => big = !big), child: const Text('Animate')),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

Curves: the feel of motion

A Curve decides the speed profile. linear is robotic. easeInOut is natural. bounceOut and elasticOut are playful. Pick one and keep it consistent in the app.

Honest note: the slide engine approximates Flutter curves with CSS timing functions, so bounce and elastic look close, not identical.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  bool right = false;
  Widget lane(String name, Curve c) => Padding(padding: const EdgeInsets.symmetric(vertical: 6), child: Stack(children: [
    Container(height: 40, color: Colors.grey.shade200, alignment: Alignment.centerLeft, padding: const EdgeInsets.only(left: 8), child: Text(name, style: const TextStyle(fontSize: 12))),
    AnimatedAlign(duration: const Duration(milliseconds: 1200), curve: c, alignment: right ? Alignment.centerRight : Alignment.centerLeft, child: const CircleAvatar(radius: 20, backgroundColor: Colors.indigo)),
  ]));
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Padding(padding: const EdgeInsets.all(16), child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
      lane('linear', Curves.linear), lane('easeInOut', Curves.easeInOut), lane('bounceOut', Curves.bounceOut), lane('elasticOut', Curves.elasticOut),
      const SizedBox(height: 16),
      FilledButton(onPressed: () => setState(() => right = !right), child: const Text('Go')),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

Explicit animation: AnimationController

A AnimationController counts from 0 to 1 over a duration. It needs a vsync (the state class with SingleTickerProviderStateMixin). Use repeat(), forward() and reverse(). Always dispose it.

Remember: forgetting dispose() leaks a ticker, and Flutter shows an error when the screen closes.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> with SingleTickerProviderStateMixin {
  late final AnimationController ctl = AnimationController(vsync: this, duration: const Duration(seconds: 2))..repeat(reverse: true);
  @override
  void dispose() { ctl.dispose(); super.dispose(); }
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: FadeTransition(opacity: ctl, child: const Icon(Icons.favorite, color: Colors.pink, size: 96))),
  );
}
void main() => runApp(const MaterialApp(home: Page()));

Hero: fly between screens

Give the same tag to a Hero on both screens. When you push the new page, Flutter flies the widget from its old place to its new place.

Honest note: the engine switches pages with a simple transition; the true flying Hero path is a Flutter-only effect.
class Home extends StatelessWidget {
  const Home({super.key});
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Gallery')),
    body: Center(child: GestureDetector(
      onTap: () => Navigator.push(context, MaterialPageRoute(builder: (c) => const Detail())),
      child: const Hero(tag: 'pic', child: CircleAvatar(radius: 40, backgroundColor: Colors.teal, child: Icon(Icons.landscape, color: Colors.white, size: 40))),
    )),
  );
}
class Detail extends StatelessWidget {
  const Detail({super.key});
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(),
    body: const Center(child: Hero(tag: 'pic', child: CircleAvatar(radius: 120, backgroundColor: Colors.teal, child: Icon(Icons.landscape, color: Colors.white, size: 120)))),
  );
}
void main() => runApp(const MaterialApp(home: Home()));

Animated explainer: Implicit vs explicit

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

Animated explainer: AnimationController timeline

Press Next to walk through it step by step, or Auto play.
EASYReal project: showing and hiding hints and bannersExample 1 of 10

Fade in and out

AnimatedOpacity fades its child when opacity changes.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  bool show = true;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
      AnimatedOpacity(duration: const Duration(milliseconds: 500), opacity: show ? 1 : 0, child: const Text('Welcome to Ranchi!', style: TextStyle(fontSize: 26))),
      const SizedBox(height: 20),
      ElevatedButton(onPressed: () => setState(() => show = !show), child: const Text('Fade')),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Make the fade take 2 seconds.
Change duration.
EASYReal project: press feedback and emphasisExample 2 of 10

Growing button

AnimatedScale grows the child. The button gets bigger on each tap and returns after.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  double s = 1;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: AnimatedScale(
      scale: s, duration: const Duration(milliseconds: 250), curve: Curves.easeOut,
      child: FilledButton(onPressed: () => setState(() => s = s == 1 ? 1.5 : 1), child: const Text('Tap me')),
    )),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Use Curves.bounceOut.
Edit the curve.
EASYReal project: selected tab labels and pricesExample 3 of 10

Animated text style

AnimatedDefaultTextStyle animates size, colour and weight together.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  bool sale = false;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
      AnimatedDefaultTextStyle(
        duration: const Duration(milliseconds: 400),
        style: TextStyle(fontSize: sale ? 40 : 22, color: sale ? Colors.red : Colors.black, fontWeight: sale ? FontWeight.bold : FontWeight.normal),
        child: const Text('Rs 499'),
      ),
      Switch(value: sale, onChanged: (v) => setState(() => sale = v)),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Add a decoration: underline when sale is on.
TextDecoration.underline.
EASYReal project: counter, tab content, status textExample 4 of 10

Switch content smoothly

AnimatedSwitcher cross-fades when its child changes. The new child needs a different key.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  int n = 0;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
      AnimatedSwitcher(duration: const Duration(milliseconds: 350), child: Text('$n', key: ValueKey(n), style: const TextStyle(fontSize: 72))),
      ElevatedButton(onPressed: () => setState(() => n++), child: const Text('+1')),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Count down instead of up.
n-- in setState.
EASYReal project: toasts and side hintsExample 5 of 10

Slide a panel in

AnimatedSlide moves a widget by a fraction of its own size. Offset(1,0) means one full width to the right.
class Page extends StatefulWidget {
  const Page({super.key});
  @override
  State<Page> createState() => _PageState();
}
class _PageState extends State<Page> {
  bool open = false;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Column(children: [
      const SizedBox(height: 60),
      ClipRect(child: AnimatedSlide(
        duration: const Duration(milliseconds: 400), curve: Curves.easeOut,
        offset: open ? Offset.zero : const Offset(-1, 0),
        child: Container(width: double.infinity, color: Colors.green, padding: const EdgeInsets.all(16), child: const Text('Order placed successfully', style: TextStyle(color: Colors.white, fontSize: 18))),
      )),
      const SizedBox(height: 20),
      FilledButton(onPressed: () => setState(() => open = !open), child: Text(open ? 'Hide' : 'Show')),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Page()));
Try it yourself: Slide from the top: Offset(0, -1).
Change the hidden offset.
MEDIUMReal project: Instagram-style like heartExample 6 of 10

Animated like button

AnimatedSwitcher swaps an outline heart for a filled one with a ScaleTransition pop. The count changes with it.
class Like extends StatefulWidget {
  const Like({super.key});
  @override
  State<Like> createState() => _LikeState();
}
class _LikeState extends State<Like> {
  bool liked = false;
  int count = 24;
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Row(mainAxisSize: MainAxisSize.min, children: [
      IconButton(
        onPressed: () => setState(() { liked = !liked; count += liked ? 1 : -1; }),
        icon: AnimatedSwitcher(
          duration: const Duration(milliseconds: 250),
          transitionBuilder: (child, anim) => ScaleTransition(scale: anim, child: child),
          child: Icon(liked ? Icons.favorite : Icons.favorite_border, key: ValueKey(liked), color: liked ? Colors.red : Colors.grey, size: 40),
        ),
      ),
      Text('$count', style: const TextStyle(fontSize: 24)),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Like()));
Try it yourself: Change to a thumbs-up icon.
Icons.thumb_up and thumb_up_outlined.
MEDIUMReal project: sync buttonsExample 7 of 10

Spinning refresh icon

RotationTransition turns a child using a controller. Press to start, press again to stop.
class Spin extends StatefulWidget {
  const Spin({super.key});
  @override
  State<Spin> createState() => _SpinState();
}
class _SpinState extends State<Spin> with SingleTickerProviderStateMixin {
  late final AnimationController c = AnimationController(vsync: this, duration: const Duration(seconds: 1));
  bool on = false;
  @override
  void dispose() { c.dispose(); super.dispose(); }
  @override
  Widget build(BuildContext context) => Scaffold(
    body: Center(child: Column(mainAxisSize: MainAxisSize.min, children: [
      RotationTransition(turns: c, child: const Icon(Icons.sync, size: 80, color: Colors.blue)),
      const SizedBox(height: 20),
      FilledButton(onPressed: () { setState(() => on = !on); if (on) { c.repeat(); } else { c.stop(); } }, child: Text(on ? 'Stop sync' : 'Start sync')),
    ])),
  );
}
void main() => runApp(const MaterialApp(home: Spin()));
Try it yourself: Spin the other way (reverse: true in repeat).
c.repeat(reverse: true).
MEDIUMReal project: FAQ and details cardsExample 8 of 10

Expandable card

AnimatedCrossFade shows two children and fades between them while the size animates. Useful for "Read more".
class Faq extends StatefulWidget {
  const Faq({super.key});
  @override
  State<Faq> createState() => _FaqState();
}
class _FaqState extends State<Faq> {
  bool open = false;
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('FAQ')),
    body: Padding(padding: const EdgeInsets.all(12), child: Card(child: InkWell(
      onTap: () => setState(() => open = !open),
      child: Padding(padding: const EdgeInsets.all(16), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        Row(children: [const Expanded(child: Text('How do I get a refund?', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16))), AnimatedRotation(turns: open ? 0.5 : 0, duration: const Duration(milliseconds: 250), child: const Icon(Icons.expand_more))]),
        AnimatedCrossFade(
          duration: const Duration(milliseconds: 300),
          crossFadeState: open ? CrossFadeState.showSecond : CrossFadeState.showFirst,
          firstChild: const SizedBox(width: double.infinity),
          secondChild: const Padding(padding: EdgeInsets.only(top: 8), child: Text('Go to Orders, tap the order and choose Refund. Money returns to your account in 5 to 7 days.')),
        ),
      ])),
    ))),
  );
}
void main() => runApp(const MaterialApp(home: Faq()));
Try it yourself: Open by default.
bool open = true.
HARDReal project: onboarding and menu screensExample 9 of 10

Staggered menu entrance

Each item uses the same controller but a different Interval, so they appear one after another. This stagger makes lists feel alive.
class Menu extends StatefulWidget {
  const Menu({super.key});
  @override
  State<Menu> createState() => _MenuState();
}
class _MenuState extends State<Menu> with SingleTickerProviderStateMixin {
  late final AnimationController c = AnimationController(vsync: this, duration: const Duration(milliseconds: 1200))..forward();
  final items = ['Dhuska', 'Litti Chokha', 'Rugra Sabzi', 'Handia Khichdi', 'Thekua'];
  @override
  void dispose() { c.dispose(); super.dispose(); }
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Jharkhand Menu'), actions: [IconButton(icon: const Icon(Icons.replay), onPressed: () => c.forward(from: 0))]),
    body: ListView(children: [
      for (var i = 0; i < items.length; i++) FadeTransition(
        opacity: CurvedAnimation(parent: c, curve: Interval(i * 0.15, i * 0.15 + 0.4, curve: Curves.easeOut)),
        child: SlideTransition(
          position: Tween<Offset>(begin: const Offset(0.3, 0), end: Offset.zero).animate(CurvedAnimation(parent: c, curve: Interval(i * 0.15, i * 0.15 + 0.4, curve: Curves.easeOut))),
          child: ListTile(leading: const Icon(Icons.restaurant), title: Text(items[i])),
        ),
      ),
    ]),
  );
}
void main() => runApp(const MaterialApp(home: Menu()));
Try it yourself: Add a sixth item and keep the stagger even.
Add a string; the Interval uses the index.
HARDReal project: product and gallery appsExample 10 of 10

Photo Hero with detail page

A grid of tiles; tapping one opens a large page. The same Hero tag per photo makes the tile fly to the big view. Each tile needs its own tag.
class Gallery extends StatelessWidget {
  const Gallery({super.key});
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Ranchi photos')),
    body: GridView.count(crossAxisCount: 2, padding: const EdgeInsets.all(8), mainAxisSpacing: 8, crossAxisSpacing: 8, children: [
      for (var i = 0; i < 4; i++) GestureDetector(
        onTap: () => Navigator.push(context, MaterialPageRoute(builder: (c) => Big(i))),
        child: Hero(tag: 'p$i', child: Container(color: Colors.primaries[i * 4].shade300, child: const Icon(Icons.photo, size: 48, color: Colors.white))),
      ),
    ]),
  );
}
class Big extends StatelessWidget {
  final int i;
  const Big(this.i, {super.key});
  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: Text('Photo ${i + 1}')),
    body: Center(child: Hero(tag: 'p$i', child: Container(width: 280, height: 280, color: Colors.primaries[i * 4].shade300, child: const Icon(Icons.photo, size: 120, color: Colors.white)))),
  );
}
void main() => runApp(const MaterialApp(home: Gallery()));
Try it yourself: Add a caption below the big photo.
Use a Column in Big; keep the Hero only around the picture.

Quick quiz

3 questions. Click an answer.
Which is an implicit animation widget?
AnimatedContainerAnimationControllerTweenTicker
What must you do with an AnimationController?
Nothingdispose() itPrint itWrap in Hero
A Hero needs on both screens the same:
ColortagSizeIcon
Score: 0 / 3

Recap: what you learned in Module 32

Implicit

Change value; Flutter animates.

Curve

easeInOut feels natural.

Controller

Explicit, needs vsync and dispose.

Transitions

Fade, Scale, Slide, Rotation.

AnimatedSwitcher

Needs a new key per child.

Hero

Same tag on two screens.

Next: the next part of the course.

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