sahandevs / xstate.dart

xstate for dart & flutter
MIT License
40 stars 6 forks source link
dart flutter state-management statecharts xstate

xstate.dart pub package Dart CI

WIP xstate for dart & flutter

Example

CD Player:

final machine = Machine.fromJson({
  "key": "cd",
  "initial": "not_loaded",
  "states": {
    "not_loaded": {
      "on": {"INSERT_CD": "loaded"}
    },
    "loaded": {
      "initial": "stopped",
      "on": {"EJECT": "not_loaded"},
      "states": {
        "stopped": {
          "on": {"PLAY": "playing"}
        },
        "playing": {
          "on": {
            "STOP": "stopped",
            "EXPIRED_END": "stopped",
            "EXPIRED_MID": "playing",
            "PAUSE": "paused"
          }
        },
        "paused": {
          "initial": "not_blank",
          "states": {
            "blank": {
              "on": {"TIMER": "not_blank"}
            },
            "not_blank": {
              "on": {"TIMER": "blank"}
            }
          },
          "on": {"PAUSE": "playing", "PLAY": "playing", "STOP": "stopped"}
        }
      }
    }
  }
});

machine.start(); // not_loaded
machine.transition('not_loaded', 'INSERT_CD'); // loaded.stopped
machine.transition('loaded.paused', 'EJECT'); // not_loaded

Roadmap & Features

Core
Tooling

image