add-effect

Add one-time Effect fields to Flutter Cubit/Bloc state for UI actions.

7|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/marcglasberg/bloc_superpowers --skill add-effect
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: add-effect
Source: https://github.com/marcglasberg/bloc_superpowers/tree/main/.claude/skills/add-effect
Command: npx skills add https://github.com/marcglasberg/bloc_superpowers --skill add-effect

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

State management for Flutter/Cubit often needs one-time side effects (snackbars, dialogs, navigation) that should trigger only once. This skill provides typed and untyped Effect fields in state to model and emit such one-time actions, ensuring consumption after read.

Core Features & Use Cases

  • Adds Effect<T> or untyped Effect fields to state for one-time notifications like snackbars, dialogs, navigation.
  • Provides patterns for emitting effects from Cubit and consuming them in widgets via context.effect(), using addPostFrameCallback for dialogs/navigation.
  • Includes examples for common effects: showSnackbar, navigate, clearText, setText, etc.

Quick Start

Define an Effect field in your state class, initialize it as spent, emit a new Effect value when you want to trigger a one-time UI action, and consume it in the widget with context.effect().

Frequently Asked Questions about add-effect

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

FAQPage Schema
How do I trigger one-time UI effects like snackbars and navigation from Flutter Cubit state?

One-time UI effects in Flutter Cubit state can be triggered by adding Effect fields to your state class. You initialize the Effect as spent, emit a new Effect value to trigger the action, and consume it in the widget using context.effect().

What is the best way to show a snackbar only once when state changes in Flutter BLoC?

The best way to show a snackbar once is using typed Effect fields in your state to model the one-time notification. Emitting an Effect value from the Cubit ensures the snackbar triggers exactly once, as the effect is consumed after being read by context.effect().

Does the add-effect pattern support both typed and untyped Effect fields for state management?

Yes, this state management pattern supports both typed Effect<T> and untyped Effect fields. Typed fields provide specific one-time UI actions like navigation, while untyped fields handle generic transient actions, ensuring safe consumption via context.effect().

How do I safely consume one-time effects in Flutter without causing UI errors?

To safely consume one-time effects in Flutter, use a single-consumer pattern for each effect and wrap UI actions like dialogs or navigation in addPostFrameCallback. This ensures the context.effect() consumption happens safely after the current build frame.

Why do my Flutter Cubit side effects trigger multiple times when rebuilding widgets?

Side effects trigger multiple times because standard state fields are continuously read during widget rebuilds. Using spent Effect initialization and consuming the Effect via context.effect() ensures the one-time UI action is only triggered and read exactly once.