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.
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.
82Compare - refena
A state management and dependency injection library inspired by Riverpod and async_redux.
87Compare - riverpod
A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
99Compare - refena_flutter
A state management and dependency injection library for Dart and Flutter.
82Compare
Works with
Packages commonly used together with statemachine: ones it builds on, ones built on it, and its own family.
- zego_uikit_prebuilt_callBuilt on statemachineFull-featured prebuilt UI kit for one-on-one and group voice and video calls with offline invitations.
- zego_uikit_prebuilt_live_streamingBuilt on statemachinePrebuilt live streaming kit with video, audio, text chat, and co-hosting support.
- zego_uikit_prebuilt_live_audio_roomBuilt on statemachinePrebuilt live audio room kit with UI and chat functionality for group voice calls.