stately_riverpod 1.0.3 copy "stately_riverpod: ^1.0.3" to clipboard
stately_riverpod: ^1.0.3 copied to clipboard

Stately implementation for Riverpod's Notifiers

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
110
points
60
downloads

Publisher

unverified uploader

Weekly Downloads

Stately implementation for Riverpod's Notifiers

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

unknown (license)

Dependencies

flutter, flutter_riverpod, riverpod, riverpod_annotation, stately_core

More

Packages that depend on stately_riverpod