跳到主内容
智客 ZICQ

技能库 智客分类:Agent 工作流 flutter-setup-declarative-routing

Flutter Setup Declarative Routing

使用类似“去路由器”的软件包配置“MatrialApp.router”,用于基于URL的高级导航。 开发需要特定深度链接和浏览器历史支持的网络应用程序或移动应用程序时使用.

41157 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

配置“ MatriaryApp.router ” ,使用类似“ go_router” 的软件包进行基于 URL 的高级导航

何时用

开发需要特定深度链接和浏览器历史支持的网络应用程序或移动应用程序

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Implementing Routing and Deep Linking、Contents、Core Concepts、Workflow: Initializing the Application and Router、Task Progress、1. Scaffold the Application。 其中含规范建议的小节:分步指令。

文件分析

文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。

官方 description(原文)

Configure `MaterialApp.router` using a package like `go_router` for advanced URL-based navigation. Use when developing web applications or mobile apps that require specific deep linking and browser history support.

Implementing Routing and Deep LinkingContentsCore ConceptsWorkflow: Initializing the Application and RouterTask Progress1. Scaffold the Application2. Configure the RouterWorkflow: Configuring Platform Deep LinkingTask ProgressIf configuring for Android:If configuring for iOS:Validation Loop

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
flutter-setup-declarative-routing
description
Configure `MaterialApp.router` using a package like `go_router` for advanced URL-based navigation. Use when developing web applications or mobile apps that require specific deep linking and browser history support.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「flutter-setup-declarative-routing」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-58cb99d98d91001c-%E5%B0%8F%E8%9D%B6-%E8%AE%BE%E7%BD%AE-%E5%AE%A3%E5%B8%83%E8%B7%AF%E7%BA%BF.html
请存为 .cursor/skills/flutter-setup-declarative-routing/SKILL.md 或 .claude/skills/flutter-setup-declarative-routing/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/flutter/agent-plugins' --list

npx skills add 'https://github.com/flutter/agent-plugins' --skill 'flutter-setup-declarative-routing'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: flutter-setup-declarative-routing description: Configure `MaterialApp.router` using a package like `go_router` for advanced URL-based navigation. Use when developing web applications or mobile apps that require specific deep linking and browser history support. metadata: model: models/gemini-3.1-pro-preview last_modified: Tue, 21 Apr 2026 21:08:03 GMT --- # Implementing Routing and Deep Linking ## Contents - [Core Concepts](#core-concepts) - [Workflow: Initializing the Application and Router](#workflow-initializing-the-application-and-router) - [Workflow: Configuring Platform Deep Linking](#workflow-configuring-platform-deep-linking) - [Workflow: Implementing Nested Navigation](#workflow-implementing-nested-navigation) - [Examples](#examples) ## Core Concepts Use the `go_router` package for declarative routing in Flutter. It provides a robust API for complex routing scenarios, deep linking, and nested navigation. - **GoRouter**: The central configuration object defining the application's route tree. - **GoRoute**: A standard route mapping a URL path to a Flutter screen. - **ShellRoute / StatefulShellRoute**: Wraps child routes in a persistent UI shell (e.g., a `BottomNavigationBar`). `StatefulShellRoute` maintains the state of parallel navigation branches. - **Path URL Strategy**: Removes the default `#` fragment from web URLs, essential for clean deep linking across platforms. ## Workflow: Initializing the Application and Router Follow this workflow to bootstrap a new Flutter application with `go_router` and configure the root routing mechanism. ### Task Progress - [ ] Create the Flutter application. - [ ] Add the `go_router` dependency. - [ ] Configure the URL strategy for web/deep linking. - [ ] Implement the `GoRouter` configuration. - [ ] Bind the router to `MaterialApp.router`. ### 1. Scaffold the Application Run the following commands to create the app and add the required routing package: ```bash flutter create cd flutter pub add go_router ``` ### 2. Configure the Router Define a top-level `GoRouter` instance. Handle authentication or state-based routing using the `redirect` parameter. ```dart import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:flutter_web_plugins/url_strategy.dart'; void main() { // Use path URL strategy to remove the '#' from web URLs usePathUrlStrategy(); runApp(const MyApp()); } final GoRouter _router = GoRouter( initialLocation: '/', routes: [ GoRoute( path: '/', builder: (context, state) => const HomeScreen(), routes: [ GoRoute( path: 'details/:id', builder: (context, state) => DetailsScreen(id: state.pathParameters['id']!), ), ], ), ], errorBuilder: (context, state) => ErrorScreen(error: state.error), ); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp.router( routerConfig: _router, title: 'Routing App', ); } } ``` ## Workflow: Configuring Platform Deep Linking Configure the native platforms to intercept specific URLs and route them into the Flutter application. ### Task Progress - [ ] Determine target platforms (iOS, Android, or both). - [ ] Apply conditional configuration for Android (Manifest + Asset Links). - [ ] Apply conditional configuration for iOS (Plist + Entitlements + AASA). - [ ] Run validator -> review errors -> fix. ### If configuring for Android: 1. **Modify `AndroidManifest.xml`**: Add the intent filter inside the `` tag for `.MainActivity`. ```xml ``` 2. **Host `assetlinks.json`**: Serve the following JSON at `https://yourdomain.com/.well-known/assetlinks.json`. ```json [{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.yourcompany.yourapp", "sha256_cert_fingerprints": ["YOUR_SHA256_FINGERPRINT"] } }] ``` ### If configuring for iOS: 1. **Modify `Info.plist`**: Opt-in to Flutter's default deep link handler. *Note: If using a third-party deep linking plugin (e.g., `app_links`), set this to `NO` to prevent conflicts.* ```xml FlutterDeepLinkingEnabled ``` 2. **Modify `Runner.entitlements`**: Add the associated domain. ```xml com.apple.developer.associated-domains applinks:yourdomain.com ``` 3. **Host `apple-app-site-association`**: Serve the following JSON (without a `.json` extension) at `https://yourdomain.com/.well-known/apple-app-site-association`. ```json { "applinks": { "apps": [], "details": [{ "appIDs": ["TEAM_ID.com.yourcompany.yourapp"], "paths": ["*"], "components": [{"/": "/*"}] }] } } ``` ### Validation Loop Run validator -> review errors -> fix. - **Android**: Test using ADB. ```bash adb shell 'am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://yourdomain.com/details/123"' com.yourcompany.yourapp ``` - **iOS**: Test using `xcrun` on a booted simulator. ```bash xcrun simctl openurl booted https://yourdomain.com/details/123 ``` ## Workflow: Implementing Nested Navigation Use `StatefulShellRoute` to implement persistent UI shells (like a bottom navigation bar) that maintain the state of their child routes. ### Task Progress - [ ] Define `StatefulShellRoute.indexedStack` in the `GoRouter` configuration. - [ ] Create `StatefulShellBranch` instances for each navigation tab. - [ ] Implement the shell widget using `StatefulNavigationShell`. ```dart final GoRouter _router = GoRouter( initialLocation: '/home', routes: [ StatefulShellRoute.indexedStack( builder: (context, state, navigationShell) { return ScaffoldWithNavBar(navigationShell: navigationShell); }, branches: [ StatefulShellBranch( routes: [ GoRoute( path: '/home', builder: (context, state) => const HomeScreen(), ), ], ), StatefulShellBranch( routes: [ GoRoute( path: '/settings', builder: (context, state) => const SettingsScreen(), ), ], ), ], ), ], ); ``` ## Examples ### High-Fidelity Shell Widget Implementation Implement the UI shell that consumes the `StatefulNavigationShell` to handle branch switching. ```dart class ScaffoldWithNavBar extends StatelessWidget { const ScaffoldWithNavBar({ required this.navigationShell, super.key, }); final StatefulNavigationShell navigationShell; void _goBranch(int index) { navigationShell.goBranch( index, // Support navigating to the initial location when tapping the active tab. initialLocation: index == navigationShell.currentIndex, ); } @override Widget build(BuildContext context) { return Scaffold( body: navigationShell, bottomNavigationBar: NavigationBar( selectedIndex: navigationShell.currentIndex, onDestinationSelected: _goBranch, destinations: const [ NavigationDestination(icon: Icon(Icons.home), label: 'Home'), NavigationDestination(icon: Icon(Icons.settings), label: 'Settings'), ], ), ); } } ``` ### Programmatic Navigation Use the `context.go()` and `context.push()` extension methods provided by `go_router`. ```dart // Replaces the current route stack with the target route (Declarative) context.go('/details/123'); // Pushes the target route onto the existing stack (Imperative) context.push('/details/123'); // Navigates using a named route and path parameters context.goNamed('details', pathParameters: {'id': '123'}); // Pops the current route context.pop(); ```

相关技能

Agent 工作流

Skill Creator

创造有效技能指南。 当用户想创造出新的技能(或更新现有的技能),以专业知识,工作流程,或工具集成来扩展克洛德的能力时,应该使用这种技能.

Agent 工作流

Clawdhub

使用ClawdHub CLI搜索,安装,更新并发布从taladhub.com的代理技能. 需要获取苍蝇上的新技能时使用,将安装的技能同步到最新版本或特定版本,或者发布 npm-instainddhub CLI 的新/更新的技能文件夹.

Agent 工作流

Agent Team Orchestration

管弦乐团多代理团队,任务设定周期,交接协议,审查工作流程. 使用时间: (1)建立2+特派员队伍,具有不同专业,(2)确定任务路线和生命周期(收录框_ spec_建设_审查_完成),(3)在特派员之间制定交接协议,(4)建立审查和质量关口,(5)管理特派员之间的交流和文物共享.

Agent 工作流

Superpowers

Spec-first,TDD,子代理驱动的软件开发工作流程. 当:(1)构建任何新功能或应用——触发脑暴_计划_子代理执行回路,(2)调试出一个bug或测试失败——触发系统性的根起过程,(3)用户说"让我们构建","帮助我计划","我想添加X",或"这个被打破",(4)完成一个功…