首页/ AI 技能 / @skilllib/skill-2014279394699718659
Skill站外收录 @skilllib/skill-2014279394699718659

riverpod-state-management

提供基于 Riverpod 2.0 的响应式状态管理能力,通过代码生成实现类型安全与编译期校验,支持异步数据流处理、不可变状态建模及清晰的三层架构分离,适用于中大型 Flutter 应用的状态治理。

0.0 (0) 557 次安装 原作者 编程导航
收录于 2026-01-22
软件开发 AI 技能

Skills.MD

# Riverpod State Management ## **Priority: P0 (CRITICAL)** Type-safe, compile-time safe reactive state management using `riverpod` and `riverpod_generator`. ## Structure ```text lib/ ├── providers/ # Global providers and services └── features/user/ ├── providers/ # Feature-specific providers └── models/ # @freezed domain models ``` ## Implementation Guidelines - **Generator First**: Use `@riverpod` annotations and `riverpod_generator`. Avoid manual `Provider` definitions. - **Immutability**: Maintain immutable states. Use `Freezed` for all state models. - **Provider Methods**: - `ref.watch()`: Use inside `build()` to rebuild on changes. - `ref.listen()`: Use for side-effects (navigation, dialogs). - `ref.read()`: Use ONLY in callbacks (onPressed). - **Asynchronous Data**: Use `AsyncNotifier` for complex async logic. Access data via `.when()` or `AsyncValue` pattern-matching. - **Architecture**: Enforce 3-layer separation (Data, Domain, Presentation). - **Linting**: Enable `riverpod_lint` and `custom_lint` for dependency cycle detection. ## Anti-Patterns - **Building Inside Providers**: Don't perform side-effects inside provider initialization. - **Context Access**: Never pass `BuildContext` into a Notifier/Provider. - **Dynamic Providers**: Avoid local provider instantiation; keep them global. ## Related Topics layer-based-clean-architecture | dependency-injection | testing

评论 0

还没有评论,来抢沙发。