fsm2 3.2.1 copy "fsm2: ^3.2.1" to clipboard
fsm2: ^3.2.1 copied to clipboard

FSM2 provides an implementation of the core design aspects of the UML state diagrams allowing both declarative transitions and dynamic transitions along with Guard Conditions.

example/main.dart

import 'dart:developer';

import 'package:fsm2/fsm2.dart';

void main() async {
  final machine = await StateMachine.create((g) => g
    ..initialState<Solid>()
    ..state<Solid>((b) => b
      ..on<OnMelted, Liquid>(sideEffect: (e) async => log('Melted'))
      ..onEnter((s, e) async => log('Entering $s State'))
      ..onExit((s, e) async => log('Exiting $s State')))
    ..state<Liquid>((b) => b
      ..onEnter((s, e) async => log('Entering $s State'))
      ..onExit((s, e) async => log('Exiting $s State'))
      ..on<OnFroze, Solid>(sideEffect: (e) async => log('Frozen'))
      ..on<OnVaporized, Gas>(sideEffect: (e) async => log('Vaporized')))
    ..state<Gas>((b) => b
      ..onEnter((s, e) async => log('Entering $s State'))
      ..onExit((s, e) async => log('Exiting $s State'))
      ..on<OnCondensed, Liquid>(sideEffect: (e) async => log('Condensed')))
    ..onTransition((from, e, to) => log(
        '''Received Event $e in State ${from!.stateType} transitioning to State ${to!.stateType}''')));
  machine
    ..analyse()
    ..export('test/smcat/water.smcat')
    ..applyEvent(OnMelted())
    ..applyEvent(OnFroze());
}

class Solid implements State {}

class Liquid implements State {}

class Gas implements State {}

class OnMelted implements Event {}

class OnFroze implements Event {}

class OnVaporized implements Event {}

class OnCondensed implements Event {}
16
likes
140
pub points
67%
popularity

Publisher

verified publisheronepub.dev

FSM2 provides an implementation of the core design aspects of the UML state diagrams allowing both declarative transitions and dynamic transitions along with Guard Conditions.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

BSD-2-Clause (license)

Dependencies

args, completer_ex, dcli_core, dcli_terminal, logger, meta, path, stacktrace_impl, synchronized, tree_iterator

More

Packages that depend on fsm2