Skip to content

Counter

The counter is the smallest complete JIntent app. A tap calls a controller method, the controller runs an intent, the intent validates through a use case, persists through a repository and updates the state. Rejections do not touch the state: they travel as effects.

Loading the demo…
Open in a new tab
  1. Press Increment a few times (a 200 ms throttle ignores presses that come faster). Each press runs an IncrementIntent that updates count in the state.
  2. Reaching 10 emits a ShowSuccessEffect: a one-time “Milestone reached” snackbar that is not part of the state.
  3. Keep pressing Increment at 10. The count stays at 10, and on every second call (a stateful validator, on purpose) the use case rejects the value. The rejection is a ShowRejectOperation effect shown as a red snackbar, not a change of state.
  • The intents under presentation/counter/intents fold an Either from the use case into an update or an effect.
  • counter_effect_handler.dart maps every effect type to its UI.
  • This demo reads state with Riverpod; the other demos use JControllerBuilder. Both work because a JController is a StateNotifier.

Related guides: effects, error handling and domain helpers.