generateDiagram method

void generateDiagram({
  1. String outputPath = 'diagram_fsm.md',
})

Generate a FSM state diagram _MermaidStateDiagram. Check on https://mermaid.js.org/intro/ to view the diagram generated. If you are using vscode, you can download the mermaid extension.

Output to mermaid diagram at outputPath.

Implementation

void generateDiagram({String outputPath = 'diagram_fsm.md'}) {
  final figure = _MermaidStateDiagram(outputPath: outputPath)
    ..addStartState(resetState.toString());

  for (final state in _states) {
    for (final entry in state.events.entries) {
      figure.addTransitions(
        state.identifier.toString(),
        entry.value.toString(),
        entry.key.name,
      );
    }

    if (state.defaultNextState != state.identifier) {
      figure.addTransitions(
        state.identifier.toString(),
        state.defaultNextState.toString(),
        '(default)',
      );
    }
  }
  figure.writeToFile();
}