Learn/Navigation/Basic Navigation

Basic Navigation

Navigate between screens using Navigator

5 min~5 min read+30 FX

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

Table of Contents

  1. 1. Complete Navigation Example
  2. 2. Navigation Stack Design Basics
  3. 3. This Lesson In Simple Words
  4. 4. Your level focus
  5. 5. One practical habit
  6. 6. Deep Understanding Guide
  7. 7. Why this lesson matters
  8. 8. Study flow for better retention
  9. 9. 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

Navigation in Flutter

Flutter uses a Navigator widget that manages a stack of screens (called routes). Think of it like a stack of cards - you can push new cards on top or pop them off to go back. The Navigator keeps track of every screen you visit, so pressing the back button always returns you to the previous one.

dart
1// Navigate to a new screen (push onto stack)
2Navigator.push(
3 context,
4 MaterialPageRoute(builder: (context) => SecondScreen()),
5);
6
7// Go back to previous screen (pop from stack)
8Navigator.pop(context);
9
10// Replace current screen
11Navigator.pushReplacement(
12 context,
13 MaterialPageRoute(builder: (context) => NewScreen()),
14);

Complete Navigation Example

Below is a full example showing two screens. The first screen has a button that pushes the second screen onto the stack, and the second screen has a button that pops itself off to go back.

dart
1class FirstScreen extends StatelessWidget {
2 @override
3 Widget build(BuildContext context) {
4 return Scaffold(
5 appBar: AppBar(title: Text('First Screen')),
6 body: Center(
7 child: ElevatedButton(
8 onPressed: () {
9 Navigator.push(
10 context,
11 MaterialPageRoute(
12 builder: (context) => SecondScreen(),
13 ),
14 );
15 },
16 child: Text('Go to Second Screen'),
17 ),
18 ),
19 );
20 }
21}
22
23class SecondScreen extends StatelessWidget {
24 @override
25 Widget build(BuildContext context) {
26 return Scaffold(
27 appBar: AppBar(title: Text('Second Screen')),
28 body: Center(
29 child: ElevatedButton(
30 onPressed: () {
31 Navigator.pop(context);
32 },
33 child: Text('Go Back'),
34 ),
35 ),
36 );
37 }
38}

Pro Tip

💡 Pro Tip

AppBar automatically shows a back button when there is a previous route to return to.

Before coding navigation, define expected user flow:

  1. Entry path (where user starts)
  2. Primary forward paths (where user can go)
  3. Back behavior expectations
  4. Replacement points (login, onboarding, success screens)

When flow is mapped first, push, pop, and replacement decisions become clear and consistent.

  • Use pushReplacement for screens that should not appear on back.
  • Avoid accidental multi-push from rapid repeated taps.
  • Ensure back behavior matches platform expectations.
  • Keep route transitions predictable across similar actions.

This Lesson In Simple Words

Navigate between screens using Navigator. 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 method adds a new screen to the navigation stack?".

Quick Glossary

  • widget: A reusable UI building block in Flutter.
  • navigator: A stack manager that controls screen transitions.
  • route: A screen entry managed by the Navigator.

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 "Basic Navigation" 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 method adds a new screen to the navigation stack?

push() adds a new route to the stack, making it the current screen.

What does Navigator.pop() do?

pop() removes the current route and returns to the previous one.

What does Navigator.pushReplacement() do?

pushReplacement removes the current route and pushes a new one, so back button won't return to the replaced screen.

What creates the route for Navigator.push()?

MaterialPageRoute creates a platform-adaptive page transition from one screen to another.

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