unyo-bloc-state-management

Manage Cubit state and orchestrate UI side effects in Flutter apps.

651|26|Updated Mar 24, 2024
One-click install
npx skills add https://github.com/K3vinb5/Unyo --skill unyo-bloc-state-management
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unyo-bloc-state-management
Source: https://github.com/K3vinb5/Unyo/tree/main/.agents/skills/unyo-bloc-state-management
Command: npx skills add https://github.com/K3vinb5/Unyo --skill unyo-bloc-state-management

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill documents a consistent pattern for managing Cubit state and orchestrating UI side effects in the Unyo Flutter app so business logic can trigger navigation, dialogs, and snackbars without holding BuildContext, avoid mutable state, and prevent memory leaks from subscriptions.

Core Features & Use Cases

  • Immutable Freezed states with effects: States implement HasEffects and include a default effects list used to express navigation and feedback intents from the cubit.
  • Cubits with EffectMixin: Cubits mix in EffectMixin, implement copyStateWithEffects and a logger, and emit state changes and AppEffect instances for the UI to handle.
  • UI effect handler & DI wiring: BlocListener reads state.effects, delegates to AppEffectHandler to execute routes/dialogs/snackbars, then calls clearEffects; cubits are registered via the DI locator and subscribe to notifiers with proper cancellation in close.

Quick Start

Create a Freezed state that implements HasEffects with a default effects list, implement a Cubit that mixes in EffectMixin and emits state.copyWith(effects: ...), register the cubit in the DI locator, and add a BlocListener in the UI to handle and clear AppEffect instances.

Frequently Asked Questions about unyo-bloc-state-management

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle navigation and snackbar side effects in Flutter cubits without storing BuildContext?

To handle side effects without BuildContext, emit navigation and snackbar intents as AppEffect instances from your cubit, then use a BlocListener in the UI to process and clear them. This pattern keeps business logic decoupled from the UI context.

What is the best way to prevent memory leaks from notifier subscriptions in Flutter cubits?

Preventing memory leaks requires cancelling notifier subscriptions within the cubit's close method. Cubits should mix in EffectMixin to manage subscription lifecycles properly, ensuring resources are released when the cubit is disposed.

How do I create immutable states with effects using Freezed for Flutter cubits?

Create immutable Freezed state classes that implement HasEffects with a default effects list. This allows your cubit to express navigation and feedback intents directly within the state, which the UI then reads and processes.

How do I wire dependency injection for cubits in a Flutter app?

Wire dependency injection by registering cubits via a DI locator. This ensures cubits are properly instantiated and available throughout the app, while also managing their lifecycle and subscription dependencies effectively.

Does this state management pattern work with mutable state in Flutter cubits?

No, this pattern requires immutable Freezed states implementing HasEffects. Cubits must implement copyStateWithEffects to emit new state instances with effects, avoiding mutable state entirely to ensure predictable UI updates and side-effect orchestration.