← Flutter tutorial

Flutter

Navigating Between Screens

Flutter treats screens as a stack. Navigator.push() adds a new screen on top, and Navigator.pop() removes the current screen to go back.

Example: navigating to a second screen

ElevatedButton(
  onPressed: () {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => const SecondScreen()),
    );
  },
  child: const Text('Go to Second Screen'),
)

Tapping the button pushes a new screen (SecondScreen) on top of the current one; a system back gesture or Navigator.pop() returns to this screen.

The "stack" mental model is worth holding onto: think of screens like a physical stack of cards, push adds a new card on top, pop removes the top card to reveal what was underneath. This is conceptually close to how Next.js's client-side <Link> navigation works too, just with Flutter making the stack explicit as part of its own API rather than mapping to browser history entries.

Example
ElevatedButton(
  onPressed: () {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => const SecondScreen()),
    );
  },
  child: const Text('Go to Second Screen'),
)
Output
Tapping the button pushes a new screen (SecondScreen) on top of the current one; a system back gesture or Navigator.pop() returns to this screen.
Ready to go further?

These free tutorials are a preview of what a Code Secure Academy cohort covers, project work and all.

Explore our tracks

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account