Skip to content
Ricardo Canastro edited this page Feb 18, 2022 · 12 revisions


Rows
Spreadsheet with superpowers!

Automata

A dart (incomplete) implementation of a finite state machine following SCXML specification.

The main highlights of automata are:

  • Declarative and type-based
  • Compound states (nested states)
  • Parallel states
  • Initial states
  • Guard conditions
  • Eventless transitions
  • Actions
  • onEntry / onExit
  • onTransition

Super quick start:

dart pub add automata

or

flutter pub add automata
import 'package:automata/automata.dart';

class Inactive extends State {}
class Active extends State {}
class OnToggle extends Event {}

final machine = StateMachine.create(
  (g) => g
    ..initial<Inactive>()
    ..state<Inactive>(
      builder: (g) => g..on<OnToggle, Active>()
    )
    ..state<Active>(
      builder: (g) => g..on<OnToggle, Inactive>()
    ),
  onTransition: (e, value) => print(
    '''
    ## Transition::
    Received Event: $e
    Value: $value
    ''',
  ),
);

machine.send(OnMelted());

Credits

While developing this packages we were heavily inspired by Tinder's StateMachine, Stately's XState and the SCXML specification.

Clone this wiki locally