transition method

CStateMachine<T> transition(
  1. String from,
  2. String to, {
  3. required bool when(),
})

Define a transition. when is checked every onUpdate while the machine is in from; first matching transition wins, evaluated in the order they were added.

Implementation

CStateMachine<T> transition(
  String from,
  String to, {
  required bool Function() when,
}) {
  if (_started) {
    throw StateError(
      'transition("$from" -> "$to") called after start() — define transitions before starting.',
    );
  }
  _requireState(from);
  _requireState(to);
  _transitions.add(CStateMachineTransition(from, to, when));
  return this;
}