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

bloc-state-management

提供基于 BLoC 模式的可预测状态管理能力,通过分离业务逻辑与 UI 实现响应式数据流控制,支持事件驱动的状态更新、流式异步处理、错误封装及并发控制,适用于中大型 Flutter 应用的稳健状态治理。

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

Skills.MD

# BLoC State Management ## **Priority: P0 (CRITICAL)** Predictable state management separating business logic from UI using `flutter_bloc`, `freezed`, or `equatable`. ## Structure ```text lib/features/auth/ ├── bloc/ │ ├── auth_bloc.dart │ ├── auth_event.dart # (@freezed or Equatable) │ └── auth_state.dart # (@freezed or Equatable) ``` ## Implementation Guidelines - **States & Events**: Use `@freezed` for union states. See [references/bloc_templates.md](references/bloc_templates.md). - **Error Handling**: Use `Failure` objects; avoid throwing exceptions. - **Async Data**: Use `emit.forEach` for streams. - **Concurrency**: Use `transformer` for event debouncing. - **Testing**: Use `blocTest` for state transition verification. - **Injection**: Register BLoCs as `@injectable` (Factory). ## Anti-Patterns - **No Manual Emit**: Do not call `emit()` inside `Future.then`; always use `await` or `emit.forEach`. - **No UI Logic**: Do not perform calculations or data formatting inside `BlocBuilder`. - **No Cross-Bloc Reference**: Do not pass a BLoC instance into another BLoC; use streams or the UI layer to coordinate. ## Related Topics layer-based-clean-architecture | dependency-injection | error-handling

评论 0

还没有评论,来抢沙发。