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
TheScaffold 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
AppBarwith titles, colors, and action buttons.
-
Implement a slide-out
Drawermenu.
-
Build a persistent
BottomNavigationBarto 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
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
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
6. Visual Learning: The Scaffold Shell
txt
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 callNavigator.pop(context)inside theListTile'sonTapto slide the Drawer closed *before* navigating.
8. Best Practices
-
Limits of Bottom Navigation: Google's Material Design guidelines state that a
BottomNavigationBarshould 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 aDrawerinstead.
9. Mini Project: Combine the UI Shell
Objective: Build an app that has an AppBar, a Drawer, and a Bottom Navigation Bar simultaneously.-
1.
Create a
StatefulWidget.
- 2. Follow the exact code in Section 5 to create a working 3-tab BottomNavigationBar.
-
3.
Once working, go to your
Scaffoldand add thedrawer:property.
-
4.
Build a
Drawerholding aListViewand a fewListTiles.
- 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.
What property of the
AppBarwidget is used to place clickable icons (like a Search or Settings icon) on the far right side of the top bar?
-
2.
What property of the
Scaffoldmagically 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
BottomNavigationBarfundamentally differs fromNavigator.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 aListViewthe preferred root child inside a Drawer?
-
Q: Walk me through the state management required to make a
BottomNavigationBarfunctional. What variable must be tracked, and where mustsetStatebe called?
13. FAQs
Q: How do I remove the "Debug" banner in the top right corner of the AppBar? A: Go to your rootMaterialApp 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 theScaffold 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.