Skip to content
Tutorials Center
My learning

Topics

Lesson 20 of 73 ยท Material, styling and assets

Material 3 Widgets Tour

A tour of the Material 3 widgets you use every day in Flutter: AppBar, buttons, Card, dialogs, SnackBar, Chip, bottom sheets and NavigationBar, with working patterns.

You could build every screen from Container, Text and GestureDetector, but you would spend weeks rebuilding what users already know: app bars, buttons with ripples, cards, dialogs, snackbars, tabs and bottom navigation. Flutter ships a large set of ready-made widgets that follow Google's Material Design 3 guidelines, and they are all in one import: package:flutter/material.dart.

This lesson is a guided tour of the ones you will use in nearly every app. You do not need to memorize every parameter. You need to know what exists, which widget to reach for, and how the pieces fit together inside a Scaffold (see Everything is a widget). Colors and fonts come from the theme, which has its own lesson.

Real vs stand-in. All Dart here is real Flutter code and is read-only on this site. The live examples are JavaScript stand-ins for the behavior behind two widgets: the snackbar queue and the dialog that returns a value.

The Material toolbox

Structure Scaffold, AppBar, NavigationBar.
Actions Buttons, FAB, chips.
Content Card, ListTile, Divider.
Overlays Dialog, SnackBar, bottom sheet.
1 / 2

Scaffold and AppBar

Scaffold is the skeleton of a screen. It has named slots, and it places each one correctly, including the space taken by the status bar and the on-screen keyboard.

DART
Scaffold(
  appBar: AppBar(
    title: const Text('Inbox'),
    actions: [
      IconButton(
        icon: const Icon(Icons.search),
        tooltip: 'Search',
        onPressed: () {},
      ),
    ],
  ),
  body: const Center(child: Text('No messages')),
  floatingActionButton: FloatingActionButton(
    onPressed: () {},
    tooltip: 'New message',
    child: const Icon(Icons.edit),
  ),
  bottomNavigationBar: null,
)
  • AppBar.title is any widget, usually a Text.
  • actions are icon buttons on the right. Give each a tooltip: it is read by screen readers and shown on long-press or hover.
  • When a screen is pushed on top of another one, AppBar adds a back button on its own (see Navigator and routes). Set leading only when you want something different.
  • FloatingActionButton (FAB) is for the single most important action. In Material 3 it has a rounded-square shape; FloatingActionButton.extended adds a label.

Buttons

Material 3 has five button styles. Choose by emphasis, not by color.

DART
Column(
  children: [
    FilledButton(onPressed: () {}, child: const Text('Save')),
    FilledButton.tonal(onPressed: () {}, child: const Text('Save draft')),
    OutlinedButton(onPressed: () {}, child: const Text('Preview')),
    TextButton(onPressed: () {}, child: const Text('Cancel')),
    ElevatedButton(onPressed: () {}, child: const Text('Share')),
  ],
)
  • FilledButton: high emphasis. Your main call to action.
  • FilledButton.tonal: medium emphasis, a softer fill.
  • ElevatedButton: medium emphasis with a shadow. Use it where a flat button would be lost against a busy background.
  • OutlinedButton: medium emphasis with a border.
  • TextButton: low emphasis. Good in dialogs and cards.
  • IconButton: an icon with a circular ripple.

Pass onPressed: null and the button is disabled and drawn grayed out. That is the standard way to disable a submit button until a form is valid. Add an icon with the .icon constructors, for example FilledButton.icon(icon: ..., label: ..., onPressed: ...).

To restyle one button, use styleFrom:

DART
FilledButton(
  style: FilledButton.styleFrom(
    minimumSize: const Size.fromHeight(48),   // full width, 48 tall
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
  ),
  onPressed: () {},
  child: const Text('Continue'),
)

If many buttons need the same look, change the theme instead of each button.

Card, ListTile and Chip

Card is a rounded surface with elevation or an outline. ListTile is the standard row with a leading widget, title, subtitle and trailing widget.

DART
Card(
  clipBehavior: Clip.antiAlias,      // so the ripple stays inside the corners
  child: ListTile(
    leading: const CircleAvatar(child: Text('AK')),
    title: const Text('Amina Khan'),
    subtitle: const Text('Sent you 3 photos'),
    trailing: const Icon(Icons.chevron_right),
    onTap: () {},
  ),
)

Chips are small pieces of information or choices:

DART
Wrap(
  spacing: 8,
  children: [
    const Chip(label: Text('Dart')),
    FilterChip(
      label: const Text('Flutter'),
      selected: true,
      onSelected: (isOn) {},
    ),
    ActionChip(label: const Text('Share'), onPressed: () {}),
    InputChip(label: const Text('[email protected]'), onDeleted: () {}),
  ],
)

Wrap lays chips in a row and moves to the next line when the row is full, which avoids the overflow you would get from a Row (Row, Column, Expanded and Flexible).

Dialogs

A dialog is a route shown on top of the current screen. showDialog opens it and returns a Future that completes with whatever you pass to Navigator.pop.

DART
Future<void> confirmDelete(BuildContext context) async {
  final bool? confirmed = await showDialog<bool>(
    context: context,
    builder: (dialogContext) => AlertDialog(
      title: const Text('Delete this note?'),
      content: const Text('You cannot undo this.'),
      actions: [
        TextButton(
          onPressed: () => Navigator.pop(dialogContext, false),
          child: const Text('Cancel'),
        ),
        FilledButton(
          onPressed: () => Navigator.pop(dialogContext, true),
          child: const Text('Delete'),
        ),
      ],
    ),
  );

  if (confirmed == true) {
    // delete it
  }
}

Note three details. The result is nullable, because tapping outside the dialog dismisses it with null. The dialog's own context is used for pop so the right route closes. And after an await, you must be sure the widget is still on screen before using its context again (the common-mistakes list in StatefulWidget and setState covers mounted).

SnackBar

A snackbar is a short, non-blocking message at the bottom, optionally with one action such as Undo. You show it through the ScaffoldMessenger, which lives above all screens so the message survives navigation:

DART
ScaffoldMessenger.of(context).showSnackBar(
  SnackBar(
    content: const Text('Note deleted'),
    action: SnackBarAction(label: 'Undo', onPressed: () {}),
  ),
);

Only one snackbar is visible at a time. Showing a second one queues it until the first leaves. Call hideCurrentSnackBar() first if you want the new message to replace the old one.

Stand-in: how a snackbar queue and a dialog result work

This stand-in is not Flutter. It models the two behaviors that surprise beginners: snackbars wait in line, and a dialog hands its answer back through a promise (a Dart Future).

JS Snackbar queue

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Three messages were sent, but only one was visible at a time. In a real app, a burst of messages can pile up, which is why you usually clear the current one first.

JS A dialog that returns a value

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The third run shows why the real code compares confirmed == true instead of using the value directly: dismissing from outside gives null, not false.

Bottom sheets

A bottom sheet slides up from the bottom. showModalBottomSheet blocks the screen behind it, like a dialog, and returns a Future too.

DART
final String? choice = await showModalBottomSheet<String>(
  context: context,
  showDragHandle: true,
  builder: (sheetContext) => SafeArea(
    child: Column(
      mainAxisSize: MainAxisSize.min,     // only as tall as its content
      children: [
        ListTile(
          leading: const Icon(Icons.photo),
          title: const Text('Choose a photo'),
          onTap: () => Navigator.pop(sheetContext, 'photo'),
        ),
        ListTile(
          leading: const Icon(Icons.camera_alt),
          title: const Text('Take a picture'),
          onTap: () => Navigator.pop(sheetContext, 'camera'),
        ),
      ],
    ),
  ),
);

MainAxisSize.min matters: a Column normally takes all the height it is offered, which would make the sheet fill the screen. For tall content such as a form, pass isScrollControlled: true.

NavigationBar is the Material 3 bottom bar for 3 to 5 top-level destinations. (It replaces the older BottomNavigationBar.) It is controlled: you tell it which index is selected, and it tells you when the user picks another.

DART
class HomeShell extends StatefulWidget {
  const HomeShell({super.key});

  @override
  State<HomeShell> createState() => _HomeShellState();
}

class _HomeShellState extends State<HomeShell> {
  int _index = 0;

  static const _pages = [
    Center(child: Text('Home')),
    Center(child: Text('Search')),
    Center(child: Text('Profile')),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(index: _index, children: _pages),
      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.search), label: 'Search'),
          NavigationDestination(icon: Icon(Icons.person_outline), selectedIcon: Icon(Icons.person), label: 'Profile'),
        ],
      ),
    );
  }
}

IndexedStack keeps all pages alive and shows one, so each tab keeps its scroll position and input. On wide screens, swap the bottom bar for a NavigationRail (see Responsive and adaptive layouts).

Drawer, BottomNavigationBar and AppBar in depth

Three pieces of navigation chrome come up in almost every app. Here is what each one does beyond the basics.

Drawer

A Drawer is a panel that slides in from the edge. Give it to Scaffold.drawer (left in left-to-right languages) or Scaffold.endDrawer, and the AppBar shows the hamburger button for you.

DART
Scaffold(
  appBar: AppBar(title: const Text('Notes')),
  drawer: Drawer(
    child: ListView(
      padding: EdgeInsets.zero,
      children: [
        const UserAccountsDrawerHeader(
          accountName: Text('Sam Rivera'),
          accountEmail: Text('[email protected]'),
          currentAccountPicture: CircleAvatar(child: Text('SR')),
        ),
        ListTile(
          leading: const Icon(Icons.archive_outlined),
          title: const Text('Archive'),
          onTap: () {
            Navigator.of(context).pop();                 // close the drawer first
            Navigator.of(context).pushNamed('/archive');
          },
        ),
      ],
    ),
  ),
  body: const NotesList(),
)

Open it from code with Scaffold.of(context).openDrawer(); the context must sit below the Scaffold, so wrap the button in a Builder or use a GlobalKey<ScaffoldState>. Close it with Navigator.pop. Material 3 also has NavigationDrawer, which takes NavigationDrawerDestinations and a selectedIndex like NavigationBar, and is the better choice for a list of app destinations. A drawer is a good home for secondary destinations (settings, archive, sign out). On wide screens a permanent side panel or NavigationRail serves better.

BottomNavigationBar versus NavigationBar

BottomNavigationBar is the older Material 2 widget. It still works and you will meet it in plenty of code, with items: [BottomNavigationBarItem(...)], currentIndex and onTap. With more than three items it switches to type: BottomNavigationBarType.fixed (or shifting, which animates colors), and unselected labels may vanish unless you set showUnselectedLabels: true. New Material 3 apps should use NavigationBar above, which has the pill-shaped indicator and consistent theming. Either way the contract is the same: the bar does not own the selected index, your state does, and pages that must keep their state belong in an IndexedStack.

JS IndexedStack keeps tabs; swapping a child does not

Press Run (or Ctrl + Enter) to see the console output here.

No output.

AppBar and SliverAppBar

AppBar has more slots than the title:

  • leading replaces the automatic hamburger or back arrow (set automaticallyImplyLeading: false to remove it).
  • actions is the row of icon buttons on the right; put a PopupMenuButton last for overflow items.
  • bottom takes a PreferredSizeWidget such as a TabBar or a search field.
  • flexibleSpace draws behind the toolbar, for gradients and images.
  • centerTitle, scrolledUnderElevation, surfaceTintColor and systemOverlayStyle control looks and the status bar icons.

AppBar sits in the Scaffold, so it never moves. When the bar should collapse, grow back or stay pinned while a list scrolls, use SliverAppBar inside a CustomScrollView (see ListView, GridView and Slivers): pinned keeps it visible, floating brings it back on any upward scroll, snap completes the motion, and expandedHeight with FlexibleSpaceBar gives the big collapsing header. Use SliverAppBar.large or .medium for Material 3 large titles.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which button is the best choice for the single main action on a screen?

    FilledButton has the highest emphasis in Material 3. Use it once per screen so the main action is obvious.
  2. 2. How do you disable a Material button?

    A button with a null onPressed (and null onLongPress) is disabled and drawn in its disabled style.
  3. 3. What does showDialog<bool> return if the user taps outside the dialog to dismiss it?

    The Future completes with null when the dialog is dismissed without Navigator.pop(value). That is why the type is bool? and you compare with == true.
  4. 4. You show three SnackBars in a row. What happens?

    ScaffoldMessenger shows one snackbar at a time and queues the rest. Call hideCurrentSnackBar first to replace the current one.
  5. 5. Why wrap the pages of a NavigationBar screen in an IndexedStack?

    IndexedStack builds all children and only paints the selected one, so inactive tabs keep their State.

Summary

  • Scaffold provides slots (appBar, body, floatingActionButton, bottomNavigationBar); AppBar adds titles, actions and a back button.
  • Pick buttons by emphasis: FilledButton, FilledButton.tonal, ElevatedButton, OutlinedButton, TextButton. onPressed: null disables them.
  • Card, ListTile and chips present content and choices; use Wrap for rows of chips.
  • showDialog and showModalBottomSheet return a Future with the popped value, or null when dismissed.
  • Snackbars go through ScaffoldMessenger and queue one at a time.
  • NavigationBar + IndexedStack builds a bottom-tab shell for 3 to 5 destinations.

Next: Themes, Colors and Dark Mode