Dart Tutorial

Navigation & Routing

Moving between screens with Navigator 1.0 and 2.0

The Navigator

In Flutter, the Navigator widget manages a stack of "Routes" (pages). You "push" a new route to go forward and "pop" a route to go back.
dart
Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => SecondPage()),
);

Named Routes

For larger apps, it's better to give each page a name (like a URL). This makes your navigation much easier to manage.
dart
// In your MaterialApp
routes: {
  '/': (context) => HomePage(),
  '/details': (context) => DetailsPage(),
}

// To navigate
Navigator.pushNamed(context, '/details');

Passing Data

Wait! You can pass data between pages when you push a new route.
dart
Navigator.push(
  context,
  MaterialPageRoute(
    builder: (context) => DetailsPage(data: 'Hello!'),
  ),
);
Wait! For complex apps (especially on the Web), Flutter provides a more advanced, declarative way to handle navigation called Navigator 2.0. It allows the app's state to directly control the navigation stack, making deep-linking and browser "Back" buttons work perfectly.
[!TIP] If Navigator 2.0 feels too complex, use a library like go_router. It's the official Google recommendation for modern, URL-based navigation.

Summary

TermDescription
RouteA screen or page in an app
PushMoving to a new page (Adding to the stack)
PopGoing back (Removing from the stack)
Deep LinkOpening the app to a specific page via a URL
go_routerThe modern standard for Flutter navigation
Best ForBuilding multi-page applications
LogicStack-based navigation
SafetyType-safe argument passing
ModernDeclarative routing is essential for Web and Desktop support
StandardUse go_router for all new professional projects
IdentityNavigation in Flutter is fully customizable and animated