replay_riverpod 0.0.1-dev.2 copy "replay_riverpod: ^0.0.1-dev.2" to clipboard
replay_riverpod: ^0.0.1-dev.2 copied to clipboard

outdated

An extension to the flutter_riverpod library which adds support for undo and redo.

Pub Star on Github style: effective dart Flutter Website Awesome Flutter Flutter Samples License: MIT

An extension to package:riverpod which adds automatic undo and redo support to riverpod states.

Like package:bloc.

Learn more at riverpod.dev!


Creating a ReplayStateNotifier #

class CounterNotifer extends ReplayStateNotifier<int> {
  CounterNotifer() : super(0);

  void increment() => emit(state + 1);
}

Using a CounterNotifer #

void main() {
  final notifier = CounterNotifer();

  // trigger a state change
  notifier.increment();
  print(notifier.state); // 1

  // undo the change
  notifier.undo();
  print(notifier.state); // 0

  // redo the change
  notifier.redo();
  print(notifier.state); // 1
}

ReplayStateNotifierMixin #

If you wish to be able to use a ReplayStateNotifier in conjuction with a different type of state notifier like HydratedStateNotifier available with the package package:hydrated_riverpod, you can use the ReplayStateNotifierMixin.

class CounterNotifier extends HydratedStateNotifier<int> with ReplayStateNotifierMixin {
  CounterNotifier() : super(0);

  void increment() => emit(state + 1);
  void decrement() => emit(state - 1);

  @override
  int fromJson(Map<String, dynamic> json) => json['value'] as int;

  @override
  Map<String, int> toJson(int state) => {'value': state};
}
3
likes
0
points
29
downloads

Publisher

unverified uploader

Weekly Downloads

An extension to the flutter_riverpod library which adds support for undo and redo.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_riverpod

More

Packages that depend on replay_riverpod