Skip to content
pubscout

side_effect_cubit

2.0.0, released 11 months ago by sontieu.dev

Adds a separate stream for one-time events in Bloc/Cubit

WASM-ready
$ flutter pub add side_effect_cubit
Source repository

What it does

It extends Bloc/Cubit to expose a dedicated stream for side effects, such as navigation or snackbars. The UI listens to this stream instead of state changes, preventing re-triggering on rebuilds.

AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • handling navigation
  • showing snackbars or dialogs
  • playing a sound
  • logging analytics events

Skip it when

  • when all events can be represented as state changes
  • when you need persistent state updates

Strengths

  • decouples side effects from state
  • prevents re-triggering on rebuilds
  • easy to test with side_effect_cubit_test

Weaknesses

  • adds extra mixin or base class boilerplate
  • requires listening widgets

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
2
class FeatureCubit extends SideEffectCubit<FeatureState, FeatureSideEffect> {
  FeatureCubit() : super(FeatureState.initial());
  void openItem(int id) => produceSideEffect(FeatureSideEffect.openItem(id));
}

Alternatives

Packages that do the same job and could replace side_effect_cubit.

Works with

Packages commonly used together with side_effect_cubit: ones it builds on, ones built on it, and its own family.