Skip to content

Transitions

Ricardo Canastro edited this page Mar 4, 2022 · 14 revisions

Defining events and transitions

Create events

In order to transition between states, you'll need to dispatch events. Very often you'll need some metadata to go along with your events so that you can guard some transitions or apply some side effects.

To create an Automata event, all you'll have to do is to extend the abstract Event class, and you're free to add any data that you want.

class Search extends Event {
  final String query;
  const Search(this.query);
}

Simple transitions

On the following example, both the transition defined in the Off and On states are simple transitions.

final machine = StateMachine.create(
  (g) => g
    ..initial<Off>()
    ..state<Off>(builder: (g) => g..on<OnToggle, On>())
    ..state<On>(builder: (g) => g..on<OnToggle, Off>())
);

Eventless transitions

TBA

Triggering a transitions

TBA (talk about how a transition is picked)

Guards

TBA

Actions

actions

TBA

onEntry

TBA

onExit

TBA

Clone this wiki locally