moai-lang-flutter by modu-ai/moai-adk
npx skills add https://github.com/modu-ai/moai-adk --skill moai-lang-flutterFlutter/Dart 开发专家 - 采用现代模式的 Dart 3.5+ 和 Flutter 3.24+。
自动触发:Flutter 项目(.dart 文件,pubspec.yaml),跨平台应用,组件开发
核心能力:
使用密封类进行模式匹配:定义一个带有泛型类型参数 T 的密封类 Result。创建包含数据字段的 Success 子类和包含错误字符串的 Failure 子类。在密封类型上使用带有模式匹配的 switch 表达式。模式使用冒号语法来提取命名字段。使用 when 关键字添加守卫子句,以便根据字段值进行条件匹配。
记录和解构:使用带有命名字段的括号为记录定义类型别名。创建返回多个值的函数作为带有位置元素的记录元组。在赋值语句左侧使用带括号的解构语法。在 for 循环中,直接使用冒号语法解构命名的记录字段。
扩展类型:使用 type 关键字定义扩展类型,将基础类型包装在括号中。为验证逻辑添加工厂构造函数。为基础值上的计算属性定义 getter。
提供者定义:导入 riverpod_annotation 并为生成的文件添加 part 指令。在函数上使用 @riverpod 注解来创建简单的提供者。返回使用 ref.read 读取其他提供者的仓库实例。通过返回 Future 类型来创建异步提供者。对于有状态的提供者,创建继承自生成的下划线类的类,重写 build 方法以设置初始状态,并添加使用 AsyncValue.guard 修改状态的方法。
组件集成:创建 ConsumerWidget 子类。在 build 方法中,将 WidgetRef 作为第二个参数接收。使用 ref.watch 来观察提供者值。使用 when 方法处理 AsyncValue,提供数据、加载和错误回调。使用 ref.invalidate 刷新数据。在 StatefulWidget 中使用 ref.listen 处理副作用,例如显示 SnackBar。
使用 Riverpod 的 StatefulWidget:继承 ConsumerStatefulWidget 和 ConsumerState。在 initState 中初始化 TextEditingController 并在 dispose 中释放。在 build 中使用 ref.listen 处理副作用。检查 isLoading 状态以在异步操作期间禁用按钮。使用 ref.read 和 notifier getter 访问 notifier 方法。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
路由器配置:使用 initialLocation 创建 GoRouter 实例。定义包含 GoRoute 对象的 routes 数组,每个对象包含 path、name 和 builder。在 routes 数组中嵌套子路由。使用 ShellRoute 实现持久导航外壳。使用 NoTransitionPage 创建 pageBuilder 以实现标签页导航。实现 redirect 回调以检查身份验证状态并返回重定向路径或 null 以允许导航。定义 errorBuilder 用于错误处理。
导航方法:使用 context.go 进行声明式导航并指定路径。使用 context.canPop 在 context.pop 之前进行检查。
Dart 实现:使用通道名称字符串定义包含 MethodChannel 和 EventChannel 常量的类。创建异步方法,这些方法在通道上调用 invokeMethod,并捕获 PlatformException。对于流式数据,在 EventChannel 上调用 receiveBroadcastStream 并将事件映射到类型化对象。使用 setMethodCallHandler 设置方法调用处理程序以接收来自原生代码的调用。
自适应布局:创建带有必需参数的 StatelessWidget,参数包括 child、destinations、selectedIndex 和 onDestinationSelected 回调。在 build 中,使用 MediaQuery.sizeOf 获取宽度。根据宽度断点使用条件返回。小于 600 像素时,返回在 bottomNavigationBar 中包含 NavigationBar 的 Scaffold。小于 840 像素时,返回包含 NavigationRail 和扩展子组件的 Row 的 Scaffold。大于 840 像素时,返回包含 NavigationDrawer 和扩展子组件的 Row 的 Scaffold。
组件测试示例:在测试主函数中,创建带有模拟提供者覆盖的 ProviderContainer。使用 tester.pumpWidget 和 UncontrolledProviderScope 包装包含待测组件的 MaterialApp。使用 find.byType 断言初始加载状态。调用 tester.pumpAndSettle 等待异步操作完成。使用 find.text 断言最终状态。
有关全面的测试模式,请参阅 examples.md。
如需全面覆盖以下内容:
请参阅:reference/adaptive.md 了解响应式布局,reference/animations.md 了解动画模式,reference/expert.md 了解专家级开发
Flutter/Dart 核心:
/flutter/flutter - Flutter 框架/dart-lang/sdk - Dart SDK状态管理:
/rrousselGit/riverpod - Riverpod 状态管理/felangel/bloc - BLoC 模式导航和存储:
/flutter/packages - go_router 和官方包/cfug/dio - HTTP 客户端/isar/isar - NoSQL 数据库moai-lang-swift - 用于平台通道的 iOS 原生集成moai-lang-kotlin - 用于平台通道的 Android 原生集成moai-domain-backend - API 集成和后端通信moai-quality-security - 移动安全最佳实践moai-essentials-debug - Flutter 调试和 DevTools每周安装量
82
仓库
GitHub 星标数
888
首次出现
2026年1月22日
安全审计
安装于
codex71
opencode70
gemini-cli67
cursor59
claude-code59
antigravity58
Flutter/Dart Development Expert - Dart 3.5+, Flutter 3.24+ with modern patterns.
Auto-Triggers: Flutter projects (.dart files, pubspec.yaml), cross-platform apps, widget development
Core Capabilities:
Pattern Matching with Sealed Classes: Define a sealed class Result with generic type parameter T. Create subclasses Success containing data field and Failure containing error string. Use switch expressions with pattern matching on the sealed type. Patterns use colon syntax to extract named fields. Add guard clauses with when keyword for conditional matching based on field values.
Records and Destructuring: Define type aliases for records using parentheses with named fields. Create functions returning multiple values as record tuples with positional elements. Use destructuring syntax with parentheses on the left side of assignment. In for loops, destructure named record fields directly using colon syntax.
Extension Types: Define extension types with the type keyword, wrapping a base type in parentheses. Add factory constructors for validation logic. Define getters for computed properties on the underlying value.
Provider Definitions: Import riverpod_annotation and add part directive for generated file. Use @riverpod annotation on functions to create simple providers. Return repository instances reading other providers with ref.read. Create async providers by returning Future types. For stateful providers, create classes extending the generated underscore class, override build method for initial state, and add methods that modify state using AsyncValue.guard.
Widget Integration: Create ConsumerWidget subclasses. In build method, receive WidgetRef as second parameter. Use ref.watch to observe provider values. Handle AsyncValue with when method providing data, loading, and error callbacks. Use ref.invalidate to refresh data. Use ref.listen in StatefulWidget for side effects like showing snackbars.
StatefulWidget with Riverpod: Extend ConsumerStatefulWidget and ConsumerState. Initialize TextEditingController in initState and dispose in dispose. Use ref.listen in build for side effects. Check isLoading state to disable buttons during async operations. Access notifier methods with ref.read and the notifier getter.
Router Configuration: Create GoRouter instance with initialLocation. Define routes array with GoRoute objects containing path, name, and builder. Nest child routes in routes array. Use ShellRoute for persistent navigation shells. Create pageBuilder using NoTransitionPage for tab navigation. Implement redirect callback checking authentication state and returning redirect path or null to allow navigation. Define errorBuilder for error handling.
Navigation methods: Use context.go for declarative navigation with path. Use context.canPop to check before context.pop.
Dart Implementation: Define class with MethodChannel and EventChannel constants using channel name strings. Create async methods that invoke methods on the channel with invokeMethod, catching PlatformException. For streaming data, call receiveBroadcastStream on EventChannel and map events to typed objects. Set up method call handler with setMethodCallHandler to receive calls from native code.
Adaptive Layouts: Create StatelessWidget with required parameters for child, destinations, selectedIndex, and onDestinationSelected callback. In build, get width using MediaQuery.sizeOf. Use conditional returns based on width breakpoints. Under 600 pixels, return Scaffold with NavigationBar in bottomNavigationBar. Under 840 pixels, return Scaffold with Row containing NavigationRail and expanded child. Above 840 pixels, return Scaffold with Row containing NavigationDrawer and expanded child.
Widget Test Example: In test main function, create ProviderContainer with overrides for mock providers. Use tester.pumpWidget with UncontrolledProviderScope wrapping MaterialApp with the widget under test. Assert initial loading state with find.byType. Call tester.pumpAndSettle to wait for async operations. Assert final state with find.text.
For comprehensive testing patterns, see examples.md.
For comprehensive coverage including:
See: reference/adaptive.md for responsive layouts, reference/animations.md for animation patterns, reference/expert.md for expert-level development
Flutter/Dart Core:
/flutter/flutter - Flutter framework/dart-lang/sdk - Dart SDKState Management:
/rrousselGit/riverpod - Riverpod state management/felangel/bloc - BLoC patternNavigation and Storage:
/flutter/packages - go_router and official packages/cfug/dio - HTTP client/isar/isar - NoSQL databasemoai-lang-swift - iOS native integration for platform channelsmoai-lang-kotlin - Android native integration for platform channelsmoai-domain-backend - API integration and backend communicationmoai-quality-security - Mobile security best practicesmoai-essentials-debug - Flutter debugging and DevToolsWeekly Installs
82
Repository
GitHub Stars
888
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex71
opencode70
gemini-cli67
cursor59
claude-code59
antigravity58
Flutter 主屏幕小组件开发指南:iOS/Android 原生小组件集成与数据通信
3,800 周安装
SQL注入测试技能:全面Web应用数据库安全漏洞评估与利用指南
201 周安装
Excel 数据分析器 - 自动检测数据结构、质量问题与统计模式,生成数据清洗报告
203 周安装
Elastic Cloud 云网络安全策略管理:IP过滤器与VPC过滤器配置指南
205 周安装
YouTube频道API工具 - 免费获取频道ID、最新视频和分页列表 | TranscriptAPI
70 周安装
Firecrawl 网页抓取工具:AI 友好的 Markdown 转换与反爬虫处理
199 周安装
阿里云 OpenClaw 最小化冒烟测试设置指南 - 验证 CLI、插件与网关状态
199 周安装