Agent skill · software engineering · affaan-m
dart-flutter-patterns
生产就绪的 Dart 和 Flutter 模式,涵盖空安全、不可变状态、异步组合、Widget 架构、流行的状态管理框架(BLoC、Riverpod、Provider)、GoRouter 导航、Dio 网络请求、Freezed 代码生成和整洁架构。
Why this skill is useful
Adds production-ready Dart and Flutter patterns with executable code snippets for state management, navigation, and error handling that are not commonly found in public documentation.
What it needs
Requires flutter installed locally. About 6k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.
What this skill does
Dart/Flutter 模式 使用场景 在以下情况使用此技能: 开始新的 Flutter 功能,需要状态管理、导航或数据访问的惯用模式 审查或编写 Dart 代码,需要空安全、密封类型或异步组合的指导 搭建新的 Flutter 项目,在 BLoC、Riverpod 或 Provider 之间做选择 实现安全的 HTTP 客户端、WebView 集成或本地存储 为 Flutter 组件、Cubit 或 Riverpod 提供者编写测试 使用认证守卫配置 GoRouter 工作原理 此技能提供按关注点组织的、可直接复制粘贴的 Dart/Flutter 代码模式: 1. 空安全 — 避免 !,优先使用 ?./??/模式匹配 2. 不可变状态 — 密封类、freezed、copyWith 3. 异步组合 — 并发 Future.wait、BuildContext 后安全使用 await 4. 组件架构 — 提取为类(而非方法)、const 传播、作用域重建 5. 状态管理 — BLoC/Cubit 事件、Riverpod 通知器和派生提供者 6. 导航 — 通过 refreshListenable 实现带响应式认证守卫的 GoRouter 7. 网络请求 — 带拦截器的 Dio、带一次性重试守卫的令牌刷新 8. 错误处理 — 全局捕获、ErrorWidget.builder、Crashlytics 集成 9. 测试 — 单元测试(BLoC 测试)、组件测试(ProviderScope 覆盖)、使用假对象而非模拟对象 示例 适用于 Dart 和 Flutter 应用程序的实用、生产就绪模式。尽可能保持库无关性,并明确覆盖最常见的生态系统包。 1. 空安全基础 优先使用模式而非感叹号操作符 避免过度使用 late 2. 不可变状态 状态层次结构的密封类 使用 Freezed 实现无模板代码的不可变性 3. 异步组合 使用 Future.wait 的结构化并发 流模式 Await 后的 BuildContext 4. 组件架构 提取为类,而非方法 const 传播 作用域重建 5. 状态管理:BLoC/Cubit 6. 状态管理:Riverpod 7. 使用 GoRouter 的导航 8. 使用 Dio 的 HTTP 请求 9. 错误处理架构 10. 测试快速参考 参考 Effective Dart: 设计 Flutter 性能最佳实践 Riverpod 文档 BLoC 库 GoRouter Freezed 技能:flutter-dart-code-review — 全面审查清单 规则:rules/dart/ — 编码风格、模式、安全性、测试、钩子
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills affaan-m/dart-flutter-patterns--0ad5a0