stately_core 1.0.2 copy "stately_core: ^1.0.2" to clipboard
stately_core: ^1.0.2 copied to clipboard

Stately core interfaces and mixins.

Stately #

A simple FSM solution for creating declarative and predictable state machines.

Designed to work with popular state management solutions to no matter what you are using you should be able to drop this right in!

stately_core pub package
stately_bloc pub package
stately_notifier pub package
stately_riverpod pub package

To get started, you can utilize stately_notifier without any extra dependencies like so:

class CounterEvent {
  const CounterEvent(this.value);

  final int value;
}

class CounterValueNotifier extends StatelyChangeNotifier<CounterEvent, int> {
  CounterValueNotifier(super.state);

  @override
  StatelyGraph<CounterEvent, int> get graph => StatelyGraph<ExampleEvent, String>(
        graph: {
          String: {
            ExampleEvent: transition((CounterEvent event, int state) => event.value),
          },
        },
      );
}

And then can use it with ValueListenableBuilder like so:

final counter = CounterValueNotifier(0);

/// ...

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ValueListenableBuilder(
          valueListenable: counter,
          builder: (ctx, state, child) {
            return Text(state.toString(), style: Theme.of(context).textTheme.headlineMedium);
          },
        ),
        ElevatedButton(onPressed: () => notifier.add(IncrementEvent()), child: Text('Increment')),
      ],
    );
  }
}

That's it!

Examples #

The examples are a great way to see how to utilize this package with a variety of state management solutions.

0
likes
120
points
69
downloads

Publisher

unverified uploader

Weekly Downloads

Stately core interfaces and mixins.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

unknown (license)

Dependencies

flutter

More

Packages that depend on stately_core