Skip to content
pubscout

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.

$ flutter pub add fsm2
Source repository

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.

  • cached_query

    Library for caching, background fetching, and managing server state in Dart and Flutter.

  • flutter_rearch

    Declarative state management and dependency injection using capsules and side effects

  • rearch

    A declarative state‑management framework with capsule‑based side effects for Flutter and Dart.

Works with

Packages commonly used together with fsm2: ones it builds on, ones built on it, and its own family.