Skip to content
pubscout

statemachine

3.4.0, released a year ago by lukas-renggli.ch

A typed state machine library for Dart and Flutter allowing explicit state definitions and transitions.

WASM-ready
$ flutter pub add statemachine
Source repository

What it does

It lets you define states, transitions, and callbacks using streams, futures, timeouts, or manual triggers. Machines can be nested and support typed identifiers for states.

AI-written summary of version 3.4.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need explicit, deterministic state flow with clear entry/exit logic
  • You want to model complex UI or business logic as a finite state machine
  • You prefer typed state identifiers over stringly‑typed solutions

Skip it when

  • Simple UI state that can be handled with setState or Provider
  • You need a full reactive state‑management solution like Bloc or Riverpod

Strengths

  • Typed states reduce runtime errors
  • Supports multiple transition sources (streams, futures, timeouts)
  • Nested machines enable hierarchical state modeling

Weaknesses

  • No built‑in UI binding; you must wire state changes manually
  • Limited ecosystem compared to larger state‑management packages

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1
import 'package:statemachine/statemachine.dart';

final machine = Machine<String>();
final start = machine.newState('start');
final active = machine.newState('active');
start.onEntry(() => print('started'));
start.onTimeout(Duration(seconds:1),()=>active.enter());
machine.start();

Alternatives

Packages that do the same job and could replace statemachine.

  • yx_state

    A state management library for Dart and Flutter applications.

  • refena

    A state management and dependency injection library inspired by Riverpod and async_redux.

  • riverpod

    A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.

  • refena_flutter

    A state management and dependency injection library for Dart and Flutter.

Works with

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