ReplayBloc<Event extends ReplayEvent, State> constructor
ReplayBloc<Event extends ReplayEvent, State> (
- State state, {
- int? limit,
A specialized Bloc which supports undo
and redo
operations.
ReplayBloc accepts an optional limit
which determines
the max size of the history.
A custom ReplayBloc can be created by extending ReplayBloc.
abstract class CounterEvent {}
class CounterIncrementPressed extends CounterEvent {}
class CounterBloc extends ReplayBloc<CounterEvent, int> {
CounterBloc() : super(0) {
on<CounterIncrementPressed>((event, emit) => emit(state + 1));
}
}
Then the built-in undo
and redo
operations can be used.
final bloc = CounterBloc();
bloc.add(CounterIncrementPressed());
bloc.undo();
bloc.redo();
The undo/redo history can be destroyed at any time by calling clear
.
See also:
- Bloc for information about the ReplayBloc superclass.
Implementation
ReplayBloc(State state, {int? limit}) : super(state) {
if (limit != null) {
this.limit = limit;
}
}