ReplayCubit<State> constructor

ReplayCubit<State>(
  1. State state, {
  2. int? limit,
})

A specialized Cubit which supports undo and redo operations.

ReplayCubit accepts an optional limit which determines the max size of the history.

A custom ReplayCubit can be created by extending ReplayCubit.

class CounterCubit extends ReplayCubit<int> {
  CounterCubit() : super(0);

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

Then the built-in undo and redo operations can be used.

final cubit = CounterCubit();

cubit.increment();
print(cubit.state); // 1

cubit.undo();
print(cubit.state); // 0

cubit.redo();
print(cubit.state); // 1

The undo/redo history can be destroyed at any time by calling clear.

See also:

Implementation

ReplayCubit(State state, {int? limit}) : super(state) {
  if (limit != null) {
    this.limit = limit;
  }
}