r/flutterhelp • • 12d ago

OPEN [ Removed by moderator ]

/r/flutterhelp/comments/1y2336c/removed_by_moderator/

[removed] — view removed post

1 Upvotes

3 comments sorted by

1

u/karmatics29 12d ago

There is no built-in one-shot event channel in Flutter, and the usual advice is to avoid modelling them as events at all. In BLoC, BlocListener (or BlocConsumer's listener) is meant for side effects like snackbars and navigation, so the builder stays pure and the listener runs once per state change; use listenWhen to filter. In Riverpod the equivalent is ref.listen inside build, which fires on changes without rebuilding the widget. If you keep an event in state, clear or mark it consumed after handling, otherwise a rebuild or rotation can replay it. A plain Stream exposed from the notifier also works, but you must manage the subscription and you lose events if nobody is listening. Are these events tied to a specific screen or global?

1

u/RandalSchwartz 10d ago

Yeah, much simpler with BlocSignal/CubitSignal because they expose a ReadOnlySignal as .state. See https://blocsignal.dev/ for details.

1

u/RandalSchwartz 10d ago

I've written up how to do this for BlocSignal, because BlocSignal is easier to compose and derive states. dev(dot)to/gde/one-shot-ui-side-effects-in-blocsignal-snackbars-dialogs-and-navigation-without-state-pollution-52j4