fsm2
3.4.1, released 4 weeks ago by onepub.dev
A Dart library for building UML‑style finite state machines with nested states and guard conditions.
What it does
FSM2 lets you define state machines using a builder API, supporting nested states, concurrent regions, guard conditions, and side‑effects. It provides runtime event handling and optional visualisation tools.
AI-written summary of version 3.4.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a lightweight, code‑first state machine for app logic
- You want declarative state definitions with support for guards and side‑effects
- You prefer a Dart‑only solution without code generation
Skip it when
- You require a full‑featured UI widget library
- You need built‑in persistence or networking capabilities
Strengths
- Supports nested and concurrent states
- Guard conditions and side‑effects are built‑in
- No code generation required
Weaknesses
- Limited to state‑machine logic, no UI components
- Documentation primarily on external site
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 10
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('Enter Liquid'))));
machine.applyEvent(OnMelted());
}Alternatives
Packages that do the same job and could replace fsm2.
- yx_state
A state management library for Dart and Flutter applications.
82Compare - cached_query
Library for caching, background fetching, and managing server state in Dart and Flutter.
90Compare - flutter_rearch
Declarative state management and dependency injection using capsules and side effects
62Compare - rearch
A declarative state‑management framework with capsule‑based side effects for Flutter and Dart.
60Compare
Works with
Packages commonly used together with fsm2: ones it builds on, ones built on it, and its own family.
- argsfsm2 depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- synchronizedfsm2 depends on itLock mechanism to prevent concurrent access to asynchronous code.
- loggerfsm2 depends on itAn extensible logger for printing formatted logs with levels, custom filters, and printers.