Visualise your FSM
It can be extremely useful to visualise you FSM and with that in mind FSM2 is able to export your FSM to the smcat format and then convert that to an svg file (image).
https://github.com/sverweij/state-machine-cat
Start by exporting your fsm2 file to an smcat file.
final machine = StateMachine.create((g) => g
..initialState(Solid())
..state<Solid>((b) => b
..on<OnMelted>((s, e) => b.transitionTo(
Liquid(),
sideEffect: (e) => print('Melted'),
)))
));
await machine.export('/path/to/file.smcat');Install
Next we need to install the visualisation tools.
pub global activate fsm2
fsm2 --installGenerate
Now you can generate svg files to show your fsm.
fms2 will now generate an svg file which you can view using any suitable svg viewer.
Display
You now have two options to view the generated svg files.
Firefox
If you have firefox installed the fsm2 can automatically display the svg using firefox:
FSM2 Viewer
We have now created a flutter desktop application call fsm2_viewer.

Page Breaks
When you FSM gets large it can be had to analyse the entire statemachine one page.
FSM2 allows you to put page breaks into rendered image.
You can add a page break at any state of coregion.
In the above example the 'Dead' will appear on two pages. It will appear on page 1 as a simple state and it will appear on page 1 as the parent state of any nested children. The blue border indicates a parent state whose contents is displayed on the next page.
Watch and refresh
Whilst working on you fsm it can be handy to see the latest version of the FSM.
You can use the fsm2 watch option to regenerate and display the latest svg file:
Now each time you regenerate the smcat file fsm2 will launch firefox with the latest version.
Script it
You can use dcli to re-generate and display your smcat file on demand.
Dcli will create a sample script and a pubspec.yaml in the tool directory. Edit the pubspec.yaml in the tool directory to include your own project:
Replace the contents of gen_smcat.dart with:
To generate and visualise your FSM.
Open two terminal windows
Use the first terminal window to regenerate the smcat file each time you change your fsm.
Use the second terminal to have fsm2 watch for changes and automatically display them.
Last updated
Was this helpful?