Get the FREE Ultimate OpenClaw Setup Guide →

flutter-navigation

Scanned
npx machina-cli add skill MADTeacher/mad-agents-skills/flutter-navigation --openclaw
Files (1)
SKILL.md
3.3 KB

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.dart

Use 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.dart

Avoid 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:

Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => DetailScreen(item: myItem)),
);

With go_router:

context.push('/details?id=123');
// Extract: final id = state.uri.queryParameters['id'];

Example: assets/passing_data.dart

Return Data From Screens

final result = await Navigator.push(
  context,
  MaterialPageRoute<String>(builder: (context) => SelectionScreen()),
);
if (!context.mounted) return;

Example: assets/returning_data.dart

Configure Deep Linking

Android: Configure AndroidManifest.xml intent filters iOS: Configure Info.plist for Universal Links Web: Automatic with go_router, choose URL strategy

For detailed setup: references/deep-linking.md

Web URL Strategy

Hash (default): example.com/#/path - no server config needed Path: example.com/path - cleaner URLs, requires server config

For server setup: references/web-navigation.md

Navigation Methods

go_router Navigation

  • context.go('/path') - replace current route
  • context.push('/path') - add to stack
  • context.pop() - go back

Navigator Navigation

  • Navigator.push() - add route to stack
  • Navigator.pop() - remove route from stack

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.md

Decision Guide

Use navigation-patterns.md for:

  • Complete comparison of navigation approaches
  • Deep linking behavior by platform
  • Web-specific considerations
  • Common patterns and anti-patterns

Source

git clone https://github.com/MADTeacher/mad-agents-skills/blob/main/flutter-navigation/SKILL.mdView on GitHub

Overview

This guide helps implement navigation and routing in Flutter across mobile and web. It covers the Navigator API, go_router, deep linking, passing/returning data, and web-specific navigation, including browser history integration.

How This Skill Works

Choose imperative Navigator API for simple apps and go_router for declarative, URL-based navigation. The guide explains configuring deep links, handling data flow between screens, and aligning with web URL strategies, while noting the recommendation to avoid named routes.

When to Use It

  • For simple apps with basic screen transitions and no deep links, use the Navigator API.
  • When you need deep linking and URL-based navigation across iOS, Android, and Web, use go_router.
  • For apps with nested navigation or multiple Navigator stacks, prefer declarative patterns with go_router and shell routes.
  • If you target the Web and want browser history support with path-based URLs, configure a URL strategy accordingly.
  • When building production-grade apps requiring authentication redirects, route guards, and robust error handling.

Quick Start

  1. Step 1: Decide between Navigator API or go_router based on deep linking needs.
  2. Step 2: Implement navigation flows and data passing (push, pop, and query parameters).
  3. Step 3: Configure deep linking and web URL strategy; test across platforms.

Best Practices

  • Avoid named routes; they limit deep link customization and browser history behavior.
  • Prefer go_router for URL-driven navigation and go-to/replace semantics; use Navigator API for simple flows.
  • Test deep linking on Android, iOS, and Web to ensure consistent behavior.
  • Implement route guards for authentication redirects and protected screens.
  • Plan for nested routes and multiple navigators to manage complex navigation stacks.

Example Use Cases

  • assets/navigator_basic.dart demonstrating Navigator.push usage.
  • assets/go_router_basic.dart showcasing context.push('/details?id=123').
  • assets/passing_data.dart showing data transfer between screens.
  • assets/returning_data.dart showing awaiting and handling returned data.
  • references/deep-linking.md and web-navigation.md for Android/iOS/Web setup.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers