Skip to main content
Flutter Basics – Complete Beginner to Advanced Guide
CHAPTER 13 Beginner

Working with AppBar, Drawer, and Bottom Navigation

Updated: May 16, 2026
25 min read

# CHAPTER 13

Working with AppBar, Drawer, and Bottom Navigation

1. Introduction

The Scaffold widget is the blueprint of a mobile screen, but so far, we have only utilized its body property to place content in the middle. Real applications require persistent navigation UI so users don't get trapped on a screen. How do you add an action button to the top right corner? How do you create a "Hamburger Menu" that slides out from the left? How do you create Instagram's classic bottom tab bar? In this chapter, we will master AppBar, Drawer, and Bottom Navigation. We will fully utilize the powers of the Scaffold widget to build industry-standard navigation shells.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Customize the AppBar with titles, colors, and action buttons.
  • Implement a slide-out Drawer menu.
  • Build a persistent BottomNavigationBar to switch between tabs.
  • Manage the state of the currently selected tab using setState.

3. The AppBar (The Top Bar)

The AppBar provides a persistent header at the top of the screen.
dart
12345678910111213
Scaffold(
  appBar: AppBar(
    title: Text("Dashboard"),
    backgroundColor: Colors.deepPurple,
    centerTitle: true, // Centers the text (default on iOS, left on Android)
    elevation: 4.0, // Adds a drop shadow
    actions: [ // Action buttons on the far right
      IconButton(icon: Icon(Icons.search), onPressed: () {}),
      IconButton(icon: Icon(Icons.settings), onPressed: () {}),
    ],
  ),
  body: Center(child: Text("Content")),
)

4. The Drawer (The Slide-out Menu)

If your app has 10 different sections, a Bottom Navigation bar is too small. You need a "Hamburger Menu" (the 3 horizontal lines). Simply adding a Drawer widget to the Scaffold magically adds the hamburger icon to your AppBar!
dart
1234567891011121314151617181920212223242526
Scaffold(
  appBar: AppBar(title: Text("My App")),
  drawer: Drawer( // Automatically adds the Hamburger Icon to the AppBar!
    child: ListView(
      padding: EdgeInsets.zero, // Removes the ugly grey bar at the top
      children: [
        DrawerHeader(
          decoration: BoxDecoration(color: Colors.blue),
          child: Text("Menu", style: TextStyle(color: Colors.white, fontSize: 24)),
        ),
        ListTile(
          leading: Icon(Icons.home),
          title: Text('Home'),
          onTap: () {
            Navigator.pop(context); // Close the drawer first!
          },
        ),
        ListTile(
          leading: Icon(Icons.person),
          title: Text('Profile'),
        ),
      ],
    ),
  ),
  body: Text("Swipe from the left edge!"),
)

5. BottomNavigationBar (The Tab Bar)

This is the modern standard for apps with 3 to 5 core screens (like Twitter or Instagram). Building this requires a StatefulWidget, because the app needs to remember *which* tab is currently active!
dart
12345678910111213141516171819202122232425262728293031323334353637383940
class MainScreen extends StatefulWidget {
  @override
  _MainScreenState createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
  int _currentIndex = 0; // Tracks the active tab

  // A list of screens to show based on the index!
  final List<Widget> _screens = [
    Center(child: Text("Home Screen")),
    Center(child: Text("Search Screen")),
    Center(child: Text("Profile Screen")),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Tab Bar Example")),
      
      // The body dynamically changes based on the selected index!
      body: _screens[_currentIndex], 
      
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex, // Tells the bar which icon to highlight
        onTap: (index) {
          // When a tab is tapped, update the state to redraw the UI!
          setState(() {
            _currentIndex = index;
          });
        },
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
          BottomNavigationBarItem(icon: Icon(Icons.search), label: "Search"),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: "Profile"),
        ],
      ),
    );
  }
}

6. Visual Learning: The Scaffold Shell

txt
1234567891011
+---------------------------------------+
| [=] (Drawer)   App Title      [Search]| <-- AppBar
+---------------------------------------+
|                                       |
|                                       | <-- Body
|             Dynamic Content           |     (Changes when tabs are clicked)
|                                       |
|                                       |
+---------------------------------------+
| [Home]        [Search]      [Profile] | <-- BottomNavigationBar
+---------------------------------------+

7. Common Mistakes

  • Not popping the Drawer: When a user clicks "Home" inside a slide-out Drawer menu, developers often immediately push the Home Screen via Navigator.push. This leaves the Drawer open *underneath* the new screen! Always call Navigator.pop(context) inside the ListTile's onTap to slide the Drawer closed *before* navigating.

8. Best Practices

  • Limits of Bottom Navigation: Google's Material Design guidelines state that a BottomNavigationBar should have no less than 3 items, and no more than 5 items. If you have 6 items, they will bunch up and look terrible. If you need 6+ navigational sections, you must use a Drawer instead.

9. Mini Project: Combine the UI Shell

Objective: Build an app that has an AppBar, a Drawer, and a Bottom Navigation Bar simultaneously.
  1. 1. Create a StatefulWidget.
  1. 2. Follow the exact code in Section 5 to create a working 3-tab BottomNavigationBar.
  1. 3. Once working, go to your Scaffold and add the drawer: property.
  1. 4. Build a Drawer holding a ListView and a few ListTiles.
  1. 5. Press Play. You now have a highly professional, interactive app shell. You can swipe from the left to reveal the Drawer, and tap the bottom icons to swap out the center content dynamically!

10. Practice Exercises

  1. 1. What property of the AppBar widget is used to place clickable icons (like a Search or Settings icon) on the far right side of the top bar?
  1. 2. What property of the Scaffold magically generates a "Hamburger" menu icon in the top left corner?

11. MCQs with Answers

Question 1

When building a BottomNavigationBar to switch between three different screens, what data type is typically used to hold the screens, and how is the active screen determined?

Question 2

According to standard UI best practices, what is the maximum number of items you should place in a BottomNavigationBar before it becomes crowded and you should switch to a Drawer instead?

12. Interview Questions

  • Q: Explain how a BottomNavigationBar fundamentally differs from Navigator.push() regarding screen architecture. Are you stacking new screens, or swapping a widget inside the existing Scaffold?
  • Q: Describe the layout and child components of a standard slide-out Drawer. Why is a ListView the preferred root child inside a Drawer?
  • Q: Walk me through the state management required to make a BottomNavigationBar functional. What variable must be tracked, and where must setState be called?

13. FAQs

Q: How do I remove the "Debug" banner in the top right corner of the AppBar? A: Go to your root MaterialApp widget (usually in main.dart) and add the property: debugShowCheckedModeBanner: false,.

14. Summary

In Chapter 13, we completed the exterior shell of our application. We unleashed the full power of the Scaffold widget. We customized the AppBar with titles and action buttons. We implemented a hidden side Drawer for secondary menu options, learning to close it properly before navigating. Finally, we architected a professional BottomNavigationBar, utilizing a StatefulWidget to track the active index and seamlessly swap out the body content.

15. Next Chapter Recommendation

Our UI looks fantastic, but as our app grows, passing data from screen to screen using constructors will become a nightmare. We need a better system. Proceed to Chapter 14: State Management Basics.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·