金色时刻 · 15:48
让好资源,触手可及
AGENT SKILL

bloc-state-management

bloc-state-management 是面向软件开发的 Agent Skill,来自 HoangNguyen0403/agent-skills-standard。查看技能说明、操作步骤与使用约定,并通过原项目了解详细用法。

Standards for predictable state management using flutter_bloc, freezed, and equatable.

SKILL.md

下载 MD ↓
nameFlutter BLoC State Management
descriptionStandards for predictable state management using flutter_bloc, freezed, and equatable.
metadata{"labels": ["flutter", "state-management", "bloc", "cubit", "freezed", "equatable"], "triggers": {"files": ["**_bloc.dart", "**_cubit.dart", "**_state.dart", "**_event.dart"], "keywords": ["BlocProvider", "BlocBuilder", "BlocListener", "Cubit", "Emitter", "transformer", "Equatable"]}}

BLoC State Management

Priority: P0 (CRITICAL)

Predictable state management separating business logic from UI using flutter_bloc, freezed, or equatable.

Structure

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.
  • 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

来源:HoangNguyen0403/agent-skills-standard · MIT 许可 · 许可原文 · MD 为来源页保存的历史版本