side_effect_cubit
2.0.0, released 11 months ago by sontieu.dev
Adds a separate stream for one-time events in Bloc/Cubit
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.
- yx_state
A state management library for Dart and Flutter applications.
82Compare - bloc_tools
Command-line tools for generating and linting bloc and cubit components.
88Compare - replay_bloc
Adds automatic undo and redo support to bloc and cubit states.
80Compare - bloc_signals_flutter
Flutter UI extensions, providers, and bindings for the bloc_signals state management library.
75Compare
Works with
Packages commonly used together with side_effect_cubit: ones it builds on, ones built on it, and its own family.