# 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 StateMachine.stream.

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](/tracking-state/stateofmind.md) stream is useful as it can be wired to a Flutter StreamBuilder.

The preferred methods are:

* When you enter a new state [onEnter](/transitions/onenter.md) is called so you can have that update your UI.
* When you leave a state [onExit](/transitions/onexit.md) is called so you can for example close a window.
* When you transition to a new state you can have a [sideEffect](/transitions/sideeffects.md) update the UI or database.

## isInState

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.

## stateOfMind

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.

## StateMachine.stream

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fsm2.onepub.dev/tracking-state/check-the-current-state.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
