TExcelTAD
Home › Flutter › MaterialApp & Scaffold

Flutter MaterialApp & Scaffold

Almost every Flutter app starts with the same two widgets. MaterialApp sets up app-wide services — theme, navigation, localisation, the app title. Scaffold provides the classic layout of a single screen: an app bar on top, a body, and optional floating button, drawer and bottom navigation.

MaterialApp

MaterialApp usually sits at the root of the tree:

flutter · try it yourself
import 'package:flutter/material.dart';

void main() => runApp(const RecipeApp());

class RecipeApp extends StatelessWidget {
  const RecipeApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Recipes',                       // used by the OS task switcher
      debugShowCheckedModeBanner: false,      // hide the DEBUG ribbon
      theme: ThemeData(
        colorSchemeSeed: Colors.orange,       // derive a whole palette
        useMaterial3: true,
      ),
      home: const Scaffold(
        body: Center(child: Text('Hungry?')),
      ),
    );
  }
}
Property Purpose
home The first screen shown
title App name used by the operating system
theme / darkTheme / themeMode Light and dark styling
routes / initialRoute Named routes for navigation
debugShowCheckedModeBanner Show or hide the debug banner

Note: Material 3 is the default since Flutter 3.16, so useMaterial3: true is optional — it is shown here for clarity.

Scaffold: the screen skeleton

Scaffold has slots for the standard parts of a screen. You fill only the ones you need:

flutter · try it yourself
import 'package:flutter/material.dart';

void main() => runApp(const MaterialApp(home: InboxScreen()));

class InboxScreen extends StatelessWidget {
  const InboxScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Inbox'),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
        actions: [
          IconButton(onPressed: () {}, icon: const Icon(Icons.search)),
          IconButton(onPressed: () {}, icon: const Icon(Icons.more_vert)),
        ],
      ),
      body: const Center(child: Text('3 unread messages')),
      floatingActionButton: FloatingActionButton.extended(
        onPressed: () {},
        icon: const Icon(Icons.edit),
        label: const Text('Compose'),
      ),
    );
  }
}

actions places icon buttons at the right end of the app bar. FloatingActionButton.extended is the wide variant with a label.

Drawer and bottom navigation

A drawer slides in from the left (the app bar adds a ☰ button automatically). A NavigationBar in bottomNavigationBar switches between top-level destinations; since the selected tab changes, the screen is stateful:

flutter · try it yourself
import 'package:flutter/material.dart';

void main() => runApp(const MaterialApp(home: HomeShell()));

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

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

class _HomeShellState extends State<HomeShell> {
  int _tab = 0;
  static const _titles = ['Home', 'Search', 'Profile'];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(_titles[_tab])),
      drawer: const Drawer(
        child: Center(child: Text('Settings')),
      ),
      body: Center(child: Text('${_titles[_tab]} page')),
      bottomNavigationBar: NavigationBar(
        selectedIndex: _tab,
        onDestinationSelected: (i) => setState(() => _tab = i),
        destinations: const [
          NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
          NavigationDestination(icon: Icon(Icons.search), label: 'Search'),
          NavigationDestination(icon: Icon(Icons.person), label: 'Profile'),
        ],
      ),
    );
  }
}

Scaffold slots at a glance

Slot Typical widget
appBar AppBar
body The main content
floatingActionButton FloatingActionButton
drawer / endDrawer Drawer
bottomNavigationBar NavigationBar, BottomAppBar
backgroundColor Screen background colour

Tip: Use one MaterialApp per app, but one Scaffold per screen. When you navigate to a new page, that page brings its own Scaffold.

Test yourself

Which widget provides theme and navigation for the whole app?

  1. Scaffold
  2. AppBar
  3. MaterialApp
  4. Container

Which Scaffold property holds icon buttons on the right side of the app bar?

  1. AppBar.actions
  2. Scaffold.trailing
  3. AppBar.buttons
  4. Scaffold.drawer

Where do you put a NavigationBar for switching between main sections?

  1. appBar
  2. drawer
  3. bottomNavigationBar
  4. floatingActionButton