executeTransitions method

  1. @visibleForOverriding
ExecutionStep<T> executeTransitions(
  1. Iterable<Transition<T>> transitions
)

Runs all the transitions in order. Rerturns an updated ExecutionStep.

Note: this opens a builder for the context, ExecutionStep, and (indirectly) History. These are all rebuilt after applying changes.

transitions list of transitions to execute. Should not be empty.

Implementation

@visibleForOverriding
ExecutionStep<T> executeTransitions(Iterable<Transition<T>> transitions) {
  if (transitions.isEmpty) return _currentStep;

  final builder = currentStep.toBuilder();
  final ctx = contextToBuilder(currentStep.context);

  builder.applyTransitions(transitions);

  // exit old
  for (var s in builder.statesToExit) {
    if (s.containsHistoryState) {
      builder.saveHistory(s);
    }
    s.exit(context, callback);
  }

  // enter new
  for (var s in builder.statesToEnter) {
    s.enter(context, callback);
    if (builder.statesForDefaultEntry.contains(s) &&
        s.initialTransition?.action != null) {
      s.initialTransition?.action!(context, callback);
    }
  }

  // perform transition actions
  for (var t in transitions) {
    if (t.action != null) t.action!(context, callback);
  }

  return builder.build(
    buildContext(ctx),
  );
}