Skip to content
pubscout

bloc_presentation

1.1.2+3, released 8 months ago by leancode.co

Dispatch single-time side effects from Bloc or Cubit without polluting state.

WASM-ready
$ flutter pub add bloc_presentation
Source repository

What it does

Provides a mixin for Blocs and Cubits to emit one-shot presentation events alongside widgets to listen to them. Prevents side effects like navigation or snackbars from cluttering the persistent UI state.

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

Use it when

  • You need to show snackbars, dialogs, or toasts after an action
  • You need to trigger navigation routes from a Bloc or Cubit
  • You want to fire fire-and-forget side effects without modifying app state

Skip it when

  • You are not using flutter_bloc or bloc in your architecture
  • The event needs to persist across configuration changes or rebuilds as part of the app state

Strengths

  • Keeps UI side effects separate from the core bloc state
  • Includes a listener widget and works well with flutter_hooks
  • Supports nullable types for optional blocs in the widget tree

Weaknesses

  • Relies on stream subscriptions which require careful lifecycle handling if not using provided widgets
  • Requires using a specific mixin on your Blocs/Cubits

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
2
class CommentCubit extends Cubit<CommentState> with BlocPresentationMixin<CommentState, CommentCubitEvent> {
  void upvote() {
    emitPresentation(const FailedToUpvote('bad connection'));
  }
}

BlocPresentationListener<CommentCubit, CommentCubitEvent>(
  listener: (context, event) {
    // handle event
  },
  child: MyWidget(),
);

Alternatives

Packages that do the same job and could replace bloc_presentation.

  • yx_state

    A state management library for Dart and Flutter applications.

  • bloc_tools

    Command-line tools for generating and linting bloc and cubit components.

  • cached_query

    Library for caching, background fetching, and managing server state in Dart and Flutter.

  • bloc_effects

    SingleLiveEvent pattern implementation for BLoC and Cubit to dispatch transient UI effects.

Works with

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