Bottom Navigation, Tabs and Drawer
Three Common Patterns
| Pattern | Widget | Use for |
|---|---|---|
| Bottom navigation | NavigationBar | 3 to 5 main sections of the app |
| Tabs | TabBar and TabBarView | Switching views inside one section |
| Side menu | Drawer | Many destinations and settings |
NavigationBar (Material 3)
dart
class MainShell extends StatefulWidget {
const MainShell({super.key});
@override
State<MainShell> createState() => _MainShellState();
}
class _MainShellState extends State<MainShell> {
int _index = 0;
final _pages = const [
HomePage(),
SearchPage(),
ProfilePage(),
];
@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'),
],
),
);
}
}
Why IndexedStack? It keeps all pages alive, so the scroll position and typed text of each tab are kept when you switch. Without it, every tab restarts when you come back.
TabBar and TabBarView
dart
class TabsPage extends StatelessWidget {
const TabsPage({super.key});
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('Messages'),
bottom: const TabBar(
tabs: [
Tab(icon: Icon(Icons.chat), text: 'Chats'),
Tab(icon: Icon(Icons.group), text: 'Groups'),
Tab(icon: Icon(Icons.call), text: 'Calls'),
],
),
),
body: const TabBarView(
children: [
Center(child: Text('Chats')),
Center(child: Text('Groups')),
Center(child: Text('Calls')),
],
),
),
);
}
}
Users can swipe left and right between tabs.
Drawer
dart
Scaffold(
appBar: AppBar(title: const Text('My App')),
drawer: Drawer(
child: ListView(
children: [
const DrawerHeader(
child: Text('Menu', style: TextStyle(fontSize: 24)),
),
ListTile(
leading: const Icon(Icons.home),
title: const Text('Home'),
onTap: () {
Navigator.pop(context); // close the drawer
// then navigate
},
),
ListTile(
leading: const Icon(Icons.settings),
title: const Text('Settings'),
onTap: () => Navigator.pop(context),
),
],
),
),
body: const Center(child: Text('Swipe from the left')),
)
Material 3 also has NavigationDrawer with built-in selection styling.
go_router with a Bottom Bar: StatefulShellRoute
dart
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) {
return Scaffold(
body: navigationShell,
bottomNavigationBar: NavigationBar(
selectedIndex: navigationShell.currentIndex,
onDestinationSelected: (i) => navigationShell.goBranch(i),
destinations: const [
NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
NavigationDestination(icon: Icon(Icons.person), label: 'Profile'),
],
),
);
},
branches: [
StatefulShellBranch(routes: [GoRoute(path: '/', builder: (c, s) => const HomePage())]),
StatefulShellBranch(routes: [GoRoute(path: '/profile', builder: (c, s) => const ProfilePage())]),
],
)
Design tip: Use a bottom bar for the top 3 to 5 sections, tabs for sub-views and a drawer only when you have many destinations. On wide screens use
NavigationRail.
Conclusion
NavigationBar, TabBar and Drawer give your app a familiar structure. Use IndexedStack to keep the page state when users switch.
Quick Summary: NavigationBar with IndexedStack for main sections, TabBar with TabBarView for sub-views and Drawer for extra menus.

