Learn/Navigation/Bottom Navigation Bar & TabBar

Bottom Navigation Bar & TabBar

Build tab-based navigation with BottomNavigationBar and TabBar

6 min~4 min read+35 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. Preserving State Across Tabs
  2. 2. This Lesson In Simple Words
  3. 3. Your level focus
  4. 4. One practical habit
  5. 5. Deep Understanding Guide
  6. 6. Why this lesson matters
  7. 7. Study flow for better retention
  8. 8. Quick Glossary

Having trouble? AI is here to help

Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.

Use the AI button at the bottom of the screen

Bottom Navigation Bar & TabBar

Two essential patterns for organizing app sections:

  • BottomNavigationBar - tabs at the bottom (Instagram, Twitter style)
  • TabBar - tabs at the top (Google Play, Settings style)

BottomNavigationBar is best for primary app sections that users switch between often. TabBar works well for categorizing content within a single screen.

dart
1// ── BottomNavigationBar ──
2class MainScreen extends StatefulWidget {
3 @override
4 State<MainScreen> createState() => _MainScreenState();
5}
6
7class _MainScreenState extends State<MainScreen> {
8 int _currentIndex = 0;
9
10 final _pages = const [
11 HomeScreen(),
12 SearchScreen(),
13 ProfileScreen(),
14 ];
15
16 @override
17 Widget build(BuildContext context) {
18 return Scaffold(
19 body: _pages[_currentIndex],
20 bottomNavigationBar: BottomNavigationBar(
21 currentIndex: _currentIndex,
22 onTap: (index) => setState(() => _currentIndex = index),
23 items: const [
24 BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
25 BottomNavigationBarItem(icon: Icon(Icons.search), label: 'Search'),
26 BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
27 ],
28 ),
29 );
30 }
31}
dart
1// ── TabBar with TabBarView ──
2class CategoryScreen extends StatelessWidget {
3 @override
4 Widget build(BuildContext context) {
5 return DefaultTabController(
6 length: 3, // number of tabs
7 child: Scaffold(
8 appBar: AppBar(
9 title: const Text('Categories'),
10 bottom: const TabBar(
11 tabs: [
12 Tab(icon: Icon(Icons.phone), text: 'Mobile'),
13 Tab(icon: Icon(Icons.laptop), text: 'Web'),
14 Tab(icon: Icon(Icons.desktop_mac), text: 'Desktop'),
15 ],
16 ),
17 ),
18 body: const TabBarView(
19 children: [
20 Center(child: Text('Mobile Content')),
21 Center(child: Text('Web Content')),
22 Center(child: Text('Desktop Content')),
23 ],
24 ),
25 ),
26 );
27 }
28}

BottomNavigationBar vs TabBar

💡 BottomNavigationBar vs TabBar

BottomNavigationBar - primary app sections (2-5 tabs, swiping not expected) TabBar - content categories within a screen (swiping between tabs is expected)

Preserving State Across Tabs

In tabbed apps, users expect each tab to remember scroll position and local state.

For BottomNavigationBar flows, consider keeping tab pages alive (for example with IndexedStack) instead of recreating each tab on every tap.

Tab Navigation Checklist

  • Tab labels are clear and task-oriented.
  • Each tab has independent state and predictable back behavior.
  • Switching tabs is instant and does not trigger heavy reloads.
  • The selected tab is visually and semantically obvious.

This Lesson In Simple Words

Build tab based navigation with BottomNavigationBar and TabBar. Navigation manages how users move between screens and return to previous states.

Your level focus

Connect each concept to real app features you can build.

One practical habit

Design route names and arguments before wiring screen UI.

Deep Understanding Guide

Why this lesson matters

Poor routing decisions create confusing UX and fragile deep-link behavior.

Study flow for better retention

  1. Map the lesson to one screen, one user action, and one expected output.
  2. Think user journey first: open app, enter data, recover state, continue flow.
  3. If you can choose between two approaches and explain why, you are improving.

Common Mistakes To Avoid

  • Passing very large objects through routes instead of IDs or lightweight models.
  • Mixing unrelated navigation methods in the same feature.
  • Losing state on back navigation due to poor route stack handling.
  • Not testing deep links and cold-start navigation paths.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Implement a three-screen flow with named routes and typed arguments.
  • Add one deep-link path and verify expected destination.
  • Write a small route guard for authenticated vs guest users.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "Which widget handles the tab switching logic for TabBar automatically?".

Quick Glossary

  • state: Data that can change and update what the user sees.
  • build: The method that describes UI for the current state.

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Lesson Completion Checklist

  • I can explain "Bottom Navigation Bar & TabBar" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Passing very large objects through routes instead of IDs or lightweight models.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

Which widget handles the tab switching logic for TabBar automatically?

DefaultTabController wraps the scaffold and manages the selected tab index automatically: no setState needed.

Where is BottomNavigationBar placed in Scaffold?

Scaffold has a bottomNavigationBar property specifically for this widget, placing it at the bottom of the screen.

How do you update BottomNavigationBar when a tab is tapped?

BottomNavigationBar's onTap gives the tapped index. Call setState to update _currentIndex, which changes the displayed page.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.

Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.

Sign in to continue with exercises and quiz for this lesson.

Sign In to Continue