Recipes
Trigger one-time Flutter effects
React to new Snapshots without replaying navigation or messages on subscription.
v0.1.0-dev.1Intermediateusecase_forge_flutter
Open source reference ↗Trigger one-time Flutter effects
Rendering and effects have different responsibilities. Keep visible state in Builder or Selector and use UseCaseListener for navigation, dialogs, snackbars, or analytics.
dart
UseCaseListener<LoginUseCase, LoginState>(
listenWhen: (previous, current) =>
previous.state.session != current.state.session,
listener: (context, snapshot) {
if (snapshot.state.session != null) {
Navigator.of(context).pop();
}
},
child: const LoginForm(),
)
Listener skips the Snapshot replayed when it subscribes, so mounting a screen does not repeat an old effect. Use UseCaseConsumer when one subscription must both build and listen; its filters remain independent.
Stream onError handles errors delivered by the Snapshot stream. It does not replace command-level error handling in core.