replay_riverpod

Last updated:

0 purchases

replay_riverpod Image
replay_riverpod Images
Add to Cart

Description:

replay riverpod

An extension to package:riverpod which adds automatic undo and redo support to riverpod states.
Like package:replay_bloc.
Learn more at riverpod.dev!

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

void increment() => emit(state + 1);
}
copied to clipboard
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
}
copied to clipboard
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};
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.