side_effect_bloc
1.0.0, released 5 years ago by georgeci.com
Extended bloc with a separate stream for one-time side effects.
What it does
Extends the standard bloc pattern to support a secondary stream specifically for side effects that should be consumed only once, such as navigation or showing snackbars. It provides mixins and base classes to easily emit and listen to side effects separately from the UI state.
AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to handle one-off events like navigation or snackbars cleanly in a BLoC architecture.
- You want to avoid state-retrigger bugs when rebuilding widgets after a one-time event occurs.
Skip it when
- You are not using the bloc or flutter_bloc packages.
- Your architecture already handles side effects through regular events or other state management approaches.
Strengths
- Clean separation of state changes from one-time side effects like navigation and toasts.
- Provides both a mixin approach for existing blocs and a base class for new ones.
- Includes convenient listener widgets for Flutter.
Weaknesses
- Adds an extra conceptual layer on top of standard BLoC.
- Limited documentation outside of basic usage examples.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
Requires existing bloc and flutter_bloc setup.
class FeatureBloc extends SideEffectBloc<FeatureEvent, FeatureState, FeatureSideEffect>{
FeatureBloc() : super(FeatureState.initial());
}Alternatives
Packages that do the same job and could replace side_effect_bloc.
- bloc_presentation
Dispatch single-time side effects from Bloc or Cubit without polluting state.
69Compare - bloc_action_listener
Adds actions stream to Bloc and Cubit to process UI events like dialogs or snackbars.
76Compare - redux_epics
Middleware for Redux that handles async side effects using Dart Streams
57Compare - bloc_effects
SingleLiveEvent pattern implementation for BLoC and Cubit to dispatch transient UI effects.
68Compare
Works with
Packages commonly used together with side_effect_bloc: ones it builds on, ones built on it, and its own family.
- blocside_effect_bloc depends on itA Dart library for implementing the BLoC pattern with Cubits and Blocs.
- flutter_blocside_effect_bloc depends on itFlutter widgets to easily integrate blocs and cubits for state management.
- providerside_effect_bloc depends on itA lightweight wrapper around InheritedWidget for state management