on<E extends Event, TOSTATE extends State> method

void on<E extends Event, TOSTATE extends State>({
  1. GuardCondition<E> condition = noopGuardCondition,
  2. SideEffect<E>? sideEffect,
  3. String? conditionLabel,
  4. String? sideEffectLabel,
})

Statically declares a transition that will occur when Event of type E is sent to machine via StateMachine.applyEvent method.

..state<MobileNoAcquired>((builder) => builder
  ..on<OnUserFound, LoggedIn>())

The condition argument implements the UML concept a 'guard condition' and allows you to register multiple transitions for a single Event. Guard conditions allow you to implement a UML 'Choice psuedostate'. When the Event is fired each transition will be evaluated in the order they are added to the State. The first transition whose guard condition method returns true will be triggered, any later conditions will not be evaluated.

..state<MobileNoAcquired>((builder) => builder
  ..on<OnUserFound, LoggedIn>(condition: (state, event)
     => event.subscribed == true))
  ..on<OnUserFound, AskForSubscription>(condition: (state, event)
    => event.subscribed == false))
```a

There MAY be only one transition with a null [condition]
and it MUST be the last
transition added to the [S]. A transition with a null [condition]
is considered the
'else' condition in that it fires if none of the transitions
 with a [condition] evaluate to true.

An [NullConditionMustBeLastException] will be thrown if you try
to register two
transitions for a given Event type with a null [condition] or you
 try to add a
transition with a non-null [condition] after adding a transition
with a null [condition].

The [conditionLabel] is optional and is only used when exporting.
The [conditionLabel] is used
to annotate the transition on the diagram.

Implementation

void on<E extends Event, TOSTATE extends State>(
    {GuardCondition<E> condition = noopGuardCondition,
    SideEffect<E>? sideEffect,
    String? conditionLabel,
    String? sideEffectLabel}) {
  final onTransition = OnTransitionDefinition<S, E, TOSTATE>(
      _stateDefinition, condition, TOSTATE, sideEffect,
      conditionLabel: conditionLabel, sideEffectLabel: sideEffectLabel);

  _stateDefinition.addTransition<E>(onTransition);
}