Navigator Basics: Push, Pop and Routes

Google Flutter 10 min min read Updated: Nov 16, 2026 Beginner
Navigator Basics: Push, Pop and Routes
Beginner Topic 1 of 4

Screens are Routes

In Flutter a screen is called a route (or page). The Navigator keeps a stack of routes, like a pile of cards. Opening a new screen puts a card on top. Going back removes the top card.

Open a New Screen

dart ElevatedButton( onPressed: () { Navigator.push( context, MaterialPageRoute(builder: (context) => const DetailPage()), ); }, child: const Text('Open details'), )

Go Back

dart Navigator.pop(context);

An AppBar on a pushed screen shows a back arrow automatically. On Android, the system back button also calls pop.

Full Two-Screen Example

dart class HomePage extends StatelessWidget { const HomePage({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Home')), body: Center( child: FilledButton( onPressed: () => Navigator.push( context, MaterialPageRoute(builder: (_) => const DetailPage()), ), child: const Text('Go to details'), ), ), ); } } class DetailPage extends StatelessWidget { const DetailPage({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Details')), body: Center( child: OutlinedButton( onPressed: () => Navigator.pop(context), child: const Text('Go back'), ), ), ); } }

Return Data to the Previous Screen

dart // Screen A: wait for the result final color = await Navigator.push<String>( context, MaterialPageRoute(builder: (_) => const PickColorPage()), ); if (!context.mounted) return; debugPrint('User picked: $color'); // Screen B: send the result back Navigator.pop(context, 'blue');

Other Useful Methods

MethodWhat it doesUse for
Navigator.pushAdd a screen on topOpen details
Navigator.popRemove the top screenGo back
Navigator.pushReplacementReplace the current screenSplash to Home
Navigator.pushAndRemoveUntilPush and clear the stackAfter login or logout
Navigator.popUntilGo back to a specific screenClose a flow
Navigator.maybePopPop only if possibleCustom back buttons
dart // After login: open Home and remove all previous screens Navigator.pushAndRemoveUntil( context, MaterialPageRoute(builder: (_) => const HomePage()), (route) => false, );

Named Routes (Simple Apps)

dart MaterialApp( initialRoute: '/', routes: { '/': (context) => const HomePage(), '/settings': (context) => const SettingsPage(), }, ) // Open it Navigator.pushNamed(context, '/settings');
What next? Named routes are fine for small apps, but they are weak for URLs, parameters and deep links. For real apps, the next lessons teach go_router, which the Flutter team recommends.

Pop Warning: BuildContext After await

After an await, the widget may have been removed. Check context.mounted (or mounted in a State class) before you use the context again, as shown above.

Conclusion

Navigator.push and pop are the foundation of all navigation. Learn them well, even if you later use go_router.

Quick Summary: Navigator is a stack. push opens a screen, pop goes back, and pushAndRemoveUntil clears the history.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators