start method

void start({
  1. void onStartupFlushed()?,
})

Compiles and freezes all schedules, initializes every system adapter, runs the Schedules.startup schedule once, then runs each state machine's OnEnter(initial).

onStartupFlushed runs before initial state entry.

Transitions queued during startup or the initial enters are not applied here; they apply at the first applyStateTransitions.

Implementation

void start({void Function()? onStartupFlushed}) {
  if (_finalized) {
    throw StateError('App has already been started.');
  }
  _validateStateSchedules();
  final detect = accessConflictPolicy != AccessConflictPolicy.ignore;
  for (final schedule in _schedules.values) {
    schedule.compile(world, detectConflicts: detect);
    accessConflicts.addAll(schedule.conflicts);
  }
  _reportAccessConflicts();
  _finalized = true;
  runSchedule(Schedules.startup);
  onStartupFlushed?.call();
  for (final machine in _stateMachines) {
    machine.enterInitial(_runStateSchedule);
  }
}