Multiple navigators

Flutter tips Published on

Hey there!

Did you know you can have more than one navigator in your Flutter app? This can be super helpful for organizing your app's flow.

Why Use Multiple Navigators?

Sometimes, you have parts of your app that are like a separate little world of pages, like an onboarding process or a login flow. Using a secondary navigator for these sections keeps things tidy and separate from your main app navigation.

Structure of Navigators

You can think of it like having a Main router navigator for your main app screens and a Secondary navigator nested inside for a specific feature, like onboarding.

Navigating to the Main Navigator

If you are deep inside a secondary navigator and need to jump back to a page in your main app flow (controlled by the root navigator), you need a special way to do it.

How to Navigate Up

You use Navigator.of(context, rootNavigator: true) to get the main navigator, and then you can push a new page onto it.

Navigator.of(context, rootNavigator: true).pushNamed("premium")

This tells Flutter to use the very first, top-level navigator, not the one you are currently in.

Example: Onboarding Flow

A common use case is an onboarding screen that might have several steps (handled by a secondary navigator). Once onboarding is done, you navigate to the main app screen using rootNavigator: true.

Save 3 months of work

Create your app using our 6 years of making Flutter apps and more than 50+ apps

kickstarter for flutter apps

Frequently Asked Questions

What is a Navigator in Flutter?

A Navigator manages a stack of pages (routes). When you go to a new page, it's pushed onto the stack. When you go back, it's popped off.

Can I have more than one Navigator in my app?

Yes, you can embed Navigators within other parts of your widget tree, allowing for multiple navigation stacks.

Why would I use multiple Navigators?

It's useful for separate flows like onboarding, login screens, or feature-specific sections where you want their navigation history to be distinct from the main app's navigation.

How do I navigate to the main (root) navigator from a nested one?

You use `Navigator.of(context, rootNavigator: true)`. Setting `rootNavigator: true` tells Flutter to look for the top-most Navigator in the widget tree.

Read more
You may also be interested in
Riverpod boilerplate  blog card image
Riverpod boilerplate
Published on 2025-05-12T08:55:19.020Z
Handling errors with futures  blog card image
Handling errors with futures
Published on 2025-05-12T09:17:16.360Z
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved