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…
Try it
Section titled “Try it”- Press Increment a few times (a 200 ms throttle ignores presses that come faster). Each press runs an
IncrementIntentthat updatescountin the state. - Reaching 10 emits a
ShowSuccessEffect: a one-time “Milestone reached” snackbar that is not part of the state. - 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
ShowRejectOperationeffect shown as a red snackbar, not a change of state.
What to look at in the code
Section titled “What to look at in the code”- The intents under
presentation/counter/intentsfold anEitherfrom the use case into an update or an effect. counter_effect_handler.dartmaps every effect type to its UI.- This demo reads state with Riverpod; the other demos use
JControllerBuilder. Both work because aJControlleris aStateNotifier.
Related guides: effects, error handling and domain helpers.