Nested States
var machine = StateMachine.create((g) => g
..initialState<S>()
..state<Alive>((b) => b
..onEnter((s, e) => print('onEnter $s as a result of $e'))
..onExit((s, e) => print('onExit $s as a result of $e'))
..on<OnBirthday, Young>(condition: (s, e) => human.age < 18, sideEffect: () => human.age++)
..on<OnBirthday, MiddleAged>(condition: (s, e) => human.age < 50, sideEffect: () => human.age++)
..on<OnBirthday, Old>(condition: (s, e) => human.age < 80, sideEffect: () => human.age++)
..on<OnDeath, Dead>()
..state<Young>((b) => b)
..state<MiddleAged>((b) => b)
..state<Old>((b) => b))
..state<Dead>((b) => b
..on<OnGood, Budist>(condition: (s, e) => s == Dead)
..on<OnUgly, SalvationArmy>(condition: (s, e) => s == InHell)
..on<OnBad, Christian>(condition: (s, e) => s == InHeaven)
..state<InHeaven>((b) => b..state<Budist>((b) => b))
..state<InHell>((b) => b..state<Christian>((b) => b..state<Catholic>((b) => b)..state<SalvationArmy>((b) => b))))
..onTransition((td) => watcher.log('${td.eventType}')));

Leaf States
Abstract States
A Nested FSM can be in multiple states!
Cascading Events
Last updated
Was this helpful?