Thuta Learning
Flutter
AdvancedMobile DevelopmentBeginner

Basic Navigation

FlutterLesson 1825 min

What you'll walk away with

  • Explain the widget, state, and lifecycle behavior of Basic Navigation
  • Test responsive, failure, and interaction cases
  • Write accessible, testable, and performant Flutter

Explain it simply

Basic Navigation, in plain language

A mobile app is rarely just one screen. You need to move between pages like Home, Detail, Profile, and Settings. In Flutter, Navigator manages the screen stack for you. push adds a new screen on top, and pop removes the current screen to go back.

Problem → Why → Solution

The problem — why this concept matters

Calling Navigator.push() from a context that isn't under a MaterialApp can cause route-related errors. Make sure MaterialApp sits at the root of your app.

A common mistake

Assuming one screen's sample output proves every rebuild, overflow, accessibility, async, and lifecycle path.

Core concept — understand how it works

Build Basic Navigation as a flow that separates UI, domain logic, data sources, and failure states. Handle loading, empty, success, error, retry, cancellation, and route restoration explicitly.

Mental model
  1. route or gesture
  2. Navigator
  3. screen and result

Explain the widget, state, and lifecycle behavior of Basic Navigation

Core syntax or pattern

dart
// On the first screen
ElevatedButton(
  child: const Text('Go to Details'),
  onPressed: () {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => const DetailScreen(),
      ),
    );
  },
)

// On the detail screen
ElevatedButton(
  child: const Text('Go Back'),
  onPressed: () {
    Navigator.pop(context);
  },
)

Build Basic Navigation as a flow that separates UI, domain logic, data sources, and failure states. Handle loading, empty, success, error, retry, cancellation, and route restoration explicitly.

Read the code step by step

  1. route or gesture// On the first screen

    A mobile app is rarely just one screen. You need to move between pages like Home, Detail, Profile, and Settings. In Flutter, Navigator manages the screen stack for you. push adds a new screen on top, and pop removes the current screen to go back.

  2. Navigator);

    Build Basic Navigation as a flow that separates UI, domain logic, data sources, and failure states. Handle loading, empty, success, error, retry, cancellation, and route restoration explicitly.

  3. screen and result)

    Run and test an original Basic Navigation example with small and large screens, text scaling, empty/loading/error states, rapid interaction, navigation restoration, and disposal cases. Use flutter analyze, widget tests, and profile mode where relevant.

Execution flow
  1. route or gesture
  2. Navigator
  3. screen and result

Success

Explain the widget, state, and lifecycle behavior of Basic Navigation

Failure

Calling Navigator.push() from a context that isn't under a MaterialApp can cause route-related errors. Make sure MaterialApp sits at the root of your app.

A mobile app is rarely just one screen. You need to move between pages like Home, Detail, Profile, and Settings. In Flutter, Navigator manages the screen stack for you. push adds a new screen on top, and pop removes the current screen to go back.

dart
// On the first screen
ElevatedButton(
  child: const Text('Go to Details'),
  onPressed: () {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => const DetailScreen(),
      ),
    );
  },
)

// On the detail screen
ElevatedButton(
  child: const Text('Go Back'),
  onPressed: () {
    Navigator.pop(context);
  },
)
You should see
Tapping "Go to Details" takes you to DetailScreen, and tapping "Go Back" returns you to the Home screen.

Next Steps

As your app gains more pages, learn Named Routes to manage them by route name.

Real-world usage

How to apply it in a real project

Run and test an original Basic Navigation example with small and large screens, text scaling, empty/loading/error states, rapid interaction, navigation restoration, and disposal cases. Use flutter analyze, widget tests, and profile mode where relevant.

Mini challenge

Build it yourself

Run and test an original Basic Navigation example with small and large screens, text scaling, empty/loading/error states, rapid interaction, navigation restoration, and disposal cases. Use flutter analyze, widget tests, and profile mode where relevant.

  • Rebuild the example without copying it
  • Test a normal input and an edge case
  • Predict the compiler or output result before running it
dart
// On the first screen
ElevatedButton(
  child: const Text('Go to Details'),
  onPressed: () {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => const DetailScreen(),
      ),
    );
  },
)

// On the detail screen
ElevatedButton(
  child: const Text('Go Back'),
  onPressed: () {
    Navigator.pop(context);
  },
)

Expected: Explain the widget, state, and lifecycle behavior of Basic Navigation

Show hint

Run and test an original Basic Navigation example with small and large screens, text scaling, empty/loading/error states, rapid interaction, navigation restoration, and disposal cases. Use flutter analyze, widget tests, and profile mode where relevant.

Quick quiz 1 / 3

What best describes the core idea of Basic Navigation?

Quick quiz 2 / 3

Which mistake should you avoid first?

Quick quiz 3 / 3

How should this be applied in a real project?

What to remember

  • route or gesture → Navigator → screen and result
  • Build Basic Navigation as a flow that separates UI, domain logic, data sources, and failure states. Handle loading, empty, success, error, retry, cancellation, and route restoration explicitly.
  • Calling Navigator.push() from a context that isn't under a MaterialApp can cause route-related errors. Make sure MaterialApp sits at the root of your app.
  • Run and test an original Basic Navigation example with small and large screens, text scaling, empty/loading/error states, rapid interaction, navigation restoration, and disposal cases. Use flutter analyze, widget tests, and profile mode where relevant.

Flutter documentation — Flutter

Easy traps

  • Calling Navigator.push() from a context that isn't under a MaterialApp can cause route-related errors. Make sure MaterialApp sits at the root of your app.
  • Assuming one screen's sample output proves every rebuild, overflow, accessibility, async, and lifecycle path.
  • Doing expensive work in build(), leaking controllers or subscriptions, or calling setState over an unnecessarily large subtree.

Hands-on Exercise

Run and test an original Basic Navigation example with small and large screens, text scaling, empty/loading/error states, rapid interaction, navigation restoration, and disposal cases. Use flutter analyze, widget tests, and profile mode where relevant.

You'll know it worked when: Tapping "Go to Details" takes you to DetailScreen, and tapping "Go Back" returns you to the Home screen.

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Basic Navigation | Thuta Learning