flutter-navigation
Original:🇺🇸 English
Translated
Comprehensive guide for Flutter navigation and routing including Navigator API, go_router, deep linking, passing/returning data, and web-specific navigation. Use when implementing screen transitions, configuring routing systems, setting up deep links, handling browser history, or managing navigation state in Flutter applications.
10installs
Added on
NPX Install
npx skill4agent add madteacher/mad-agents-skills flutter-navigationTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Flutter Navigation
Overview
Implement navigation and routing in Flutter applications across mobile and web platforms. Choose the right navigation approach, configure deep linking, manage data flow between screens, and handle browser history integration.
Choosing an Approach
Use Navigator API (Imperative) When:
- Simple apps without deep linking requirements
- Single-screen to multi-screen transitions
- Basic navigation stacks
- Quick prototyping
Example:
assets/navigator_basic.dartUse go_router (Declarative) When:
- Apps requiring deep linking (iOS, Android, Web)
- Web applications with browser history support
- Complex navigation patterns with multiple Navigator widgets
- URL-based navigation needed
- Production applications with scalable architecture
Example:
assets/go_router_basic.dartAvoid Named Routes
Flutter team does NOT recommend named routes. They have limitations:
- Cannot customize deep link behavior
- No browser forward button support
- Always pushes new routes regardless of current state
Common Tasks
Pass Data Between Screens
With Navigator:
dart
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DetailScreen(item: myItem)),
);With go_router:
dart
context.push('/details?id=123');
// Extract: final id = state.uri.queryParameters['id'];Example:
assets/passing_data.dartReturn Data From Screens
dart
final result = await Navigator.push(
context,
MaterialPageRoute<String>(builder: (context) => SelectionScreen()),
);
if (!context.mounted) return;Example:
assets/returning_data.dartConfigure Deep Linking
Android: Configure intent filters
iOS: Configure for Universal Links
Web: Automatic with go_router, choose URL strategy
AndroidManifest.xmlInfo.plistFor detailed setup:
references/deep-linking.mdWeb URL Strategy
Hash (default): - no server config needed
Path: - cleaner URLs, requires server config
example.com/#/pathexample.com/pathFor server setup:
references/web-navigation.mdNavigation Methods
go_router Navigation
- - replace current route
context.go('/path') - - add to stack
context.push('/path') - - go back
context.pop()
Navigator Navigation
- - add route to stack
Navigator.push() - - remove route from stack
Navigator.pop()
Advanced Topics
Route Guards: Implement authentication redirects
Nested Routes: Create shell routes with shared UI
Error Handling: Handle 404 and navigation errors
Multiple Navigators: Manage independent navigation stacks
For advanced patterns:
references/go_router-guide.mdDecision Guide
Use navigation-patterns.md for:
- Complete comparison of navigation approaches
- Deep linking behavior by platform
- Web-specific considerations
- Common patterns and anti-patterns