state_machine
3.0.3, released 9 months ago by workiva.com
Finite state machine library to define legal state transitions and listen to state changes.
What it does
Allows developers to create finite state machines, define legal state transitions, and handle state entrances, departures, and payloads. It throws exceptions for illegal transitions and supports transition cancellation conditions.
AI-written summary of version 3.0.3, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to enforce strict rules on how an object or UI component transitions between states.
- You want to listen to state entrances, departures, and transitions with optional data payloads.
Skip it when
- You are looking for widget-level state management solutions like Provider or Bloc for Flutter UI rebuilding.
- Your state flow is simple enough that boolean flags or standard enums suffice.
Strengths
- Prevents illegal state transitions by design.
- Supports cancellation conditions and wildcards for transitions.
- Exposes streams for state entrances and departures.
Weaknesses
- Limited documentation on advanced architectural patterns.
- Unclear active maintenance status with unknown license.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
StateMachine light = new StateMachine('light');
State isOn = light.newState('on');
State isOff = light.newState('off');
StateTransition turnOn = light.newStateTransition('turnOn', [isOff], isOn);
light.start(isOff);
turnOn();Alternatives
Packages that do the same job and could replace state_machine.
- 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 - statemachine
A typed state machine library for Dart and Flutter allowing explicit state definitions and transitions.
73Compare - saga_state_machine
A MassTransit-style state machine framework for Dart with a fluent builder API.
51Compare