Flutter Sep 30, 2020

Learning Flutter's new navigation and routing system

Article Summary

John Ryan from Flutter's team tackles one of mobile dev's messiest problems: navigation. But the solution might be more complex than the problem itself.

Flutter introduced Navigator 2.0 to give developers declarative control over navigation stacks and URL parsing—critical for web support. This deep-dive tutorial walks through the new Router, RouterDelegate, and RouteInformationParser APIs with working code examples.

Key Takeaways

Critical Insight

Flutter's new navigation system offers powerful declarative control and web URL support, but requires significantly more boilerplate than the original imperative API.

The article includes a nested router example that shows how to handle BottomAppBar navigation alongside stacked views—a pattern that stumped developers for years.

About This Article

Problem

Before Navigator 2.0, Flutter developers struggled with complex navigation tasks. They couldn't push or pop multiple pages at once, and removing pages underneath the current one was difficult. GitHub issue #12146 documented these problems.

Solution

John Ryan's article explains how to use the Router widget with RouteInformationParser and RouterDelegate classes. These classes parse browser URLs into custom data types like BookRoutePath. This approach lets you manage the page stack declaratively instead of using imperative push and pop calls.

Impact

The new system keeps web apps in sync with the URL bar and handles back button presses from both the app and browser. However, setting it up takes about 250 lines of code for a basic two-page application, which is more work than some simpler alternatives.