Check the current state

There are a number of methods for checking the current state of the StateMachine.

  • StateMachine.isInState

  • StateOfMind.isInState

  • StateMachine.stateOfMind

  • Subscribing to

Generally, you should not have to interact with any of these methods too often, rather you should rely on sideEffects and the onEnter and onExit methods to make 'things' happen although the SateOfMind stream is useful as it can be wired to a Flutter StreamBuilder.

The preferred methods are:

  • When you enter a new state onEnter is called so you can have that update your UI.

  • When you leave a state onExit is called so you can for example close a window.

  • When you transition to a new state you can have a sideEffect update the UI or database.


Using isInState allows you to check the current state of the machine at any time.

Remember that due to Nested States and Concurrent States an FSM can actually be in multiple states at the one time.

When using isInState you should usually target the state lowest in the tree (where the top of the tree is the root - it's an upside-down tree).

You can also call isInState multiple times to determine what other states the FSM is in.

If you need to know multiple states then stateOfMind is a better option.


Note: This is a work in progress and currently only returns the state that was directly transitioned into (referred to internally as the currentState but that's not quite a true reflection).

A call to stateOfMind returns a StateOfMind object that contains all of the nested ancestor states as well as any concurrent states in a tree structure.

The stream can be used with a Flutter StreamBuilder to process each state update as it occurs.

Last updated