FLUTTER ECOSYSTEM

onepub-dev/fsm2

FMS2 は、UML 状態図のコア設計要素の Dart 実装を提供しています。

fsm2 のプロジェクト画像
Stars
53
Forks
6
最終プッシュ(UTC)
2026/08/16
プロジェクト状態
公開中
OnePub GitHub avatar
GITHUB Organization

OnePub ↗

言語Dart

技術トピック

使用している依存関係

依存関係一覧 14 件
  • args^2.4.2
  • completer_ex^4.0.0
  • dcli_core^9.0.2
  • dcli_terminal^9.0.2
  • logger^2.0.1
  • meta^1.6.0
  • path^1.7.0
  • stacktrace_impl^2.0.1
  • synchronized^3.0.0
  • tree_iterator^3.0.0
  • dcli開発用^9.0.2
  • lint_hard開発用^8.0.0
  • mockito開発用^5.0.0
  • test開発用^1.0.0

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

README を開く / 閉じる

FSM2 provides an implementation of the core design aspects of the UML2 state diagrams.

FMS2 supports:

  • Nested States
  • Concurrent Regions
  • Guard Conditions
  • sideEffects
  • onEnter/onExit
  • streams
  • static analysis tools
  • visualisation tools.

Overview

FSM2 uses a builder to delcare each state machine.

Your application may declare as many statemachines as necessary.

Example

import 'package:fsm2/fsm2.dart';

void main() {
  final machine = StateMachine.create((g) => g
    ..initialState(Solid())
    ..state<Solid>((b) => b
      ..on<OnMelted, Liquid>(sideEffect: (e) async => print("I'm melting"))
    ..state<Liquid>((b) {})
 ));

The above examples creates a Finite State Machine (machine) which declares its initial state as being Solid and then declares a single transition which occurs when the event OnMelted event is triggered causing a transition to a new state Liquid.

To trigger an event:

machine.applyEvent(OnMelted());

Documentation

Full documentation is available on gitbooks at:

https://fsm2.onepub.dev/

Example 2

A simple example showing the life cycle of H2O.

import 'package:fsm2/fsm2.dart';

void main() {
  final machine = StateMachine.create((g) => g
    ..initialState(Solid())
    ..state<Solid>((b) => b
      ..on<OnMelted, Liquid>(sideEffect: (e) => print('Melted'),
          )))
    ..state<Liquid>((b) => b
      ..onEnter((s, e) => print('Entering ${s.runtimeType} State'))
      ..onExit((s, e) => print('Exiting ${s.runtimeType} State'))
      ..on<OnFroze, Solid>(sideEffect: (e) => print('Frozen')))
      ..on<OnVaporized, Gas>(sideEffect: (e) => print('Vaporized'))))
    ..state<Gas>((b) => b
      ..on<OnCondensed, Liquid>(sideEffect: (e) => print('Condensed'))))
    ..onTransition((t) => print(
        'Received Event ${t.event.runtimeType} in State ${t.fromState.runtimeType} transitioning to State ${t.toState.runtimeType}')));

  await machine.complete;

  ///   machine.isInState<Hard>()

  print(machine.isInSt<Solid>); // TRUE

  machine.transition(OnMelted());
  print(machine.isInState<Liquid>); // TRUE

  machine.transition(OnFroze());
  print(machine.isInState<Solid>); // TRUE
}

Credits:

FMS2 is derived from the FSM library which in turn was inspired by Tinder StateMachine library.