# Simple Transitions

Simple transitions are declared using the 'on' builder.

```dart
import 'package:fsm2/fsm2.dart';

void main() {
  final machine = StateMachine.create((g) => g
    ..initialState(Solid())
    ..state<Solid>((b) => b
      ..on<OnMelted, Liquid>())
 );
```

The above examples creates a Finite State Machine (machine) which declares its initial state as being `Solid` and then declares a single transition Solid -> Liquid when the event `OnMelted` is applied to the FSM.

We can now write a unit test that validates our state machine when \`machine.applyEvent(OnMelted())\` is called.

```dart
import 'package:fsm2/fsm2.dart';
import 'package:test/test.dart';

test('test transition', () async {
  
  /// build the state machine.
  final machine = StateMachine.create((g) => g
    ..initialState(Solid())
    ..state<Solid>((b) => b
      ..on<OnMelted, Liquid>())
      
  /// check its initial state
  expect(machine.isInState<Solid>(), equals(true));

  /// trigger the state change
  await machine.applyEvent(OnMelted());

  /// check we arrived in the expected state.
  expect(machine.isInState<Liquid>(), equals(true));
});
```

### Many transitions

A State can have any number of `on` transitions including multiple transitions for the same Event providing a guard conditions is used.

See the section on [Guard Conditions](/transitions/guard-conditions.md) for details on defining conditional transitions.


---

# 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/transitions/static-transitions.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.
