replay_cubit 0.2.0 replay_cubit: ^0.2.0 copied to clipboard
An extension to the cubit state management library which adds support for undo and redo.
An extension to the cubit state management library which adds support for undo and redo.
Creating a ReplayCubit #
class CounterCubit extends ReplayCubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
}
Using a ReplayCubit #
void main() {
final cubit = CounterCubit();
// trigger a state change
cubit.increment();
print(cubit.state); // 1
// undo the change
cubit.undo();
print(cubit.state); // 0
// redo the change
cubit.redo();
print(cubit.state); // 1
}
ReplayMixin #
If you wish to be able to use a ReplayCubit
in conjuction with a different type of cubit like HydratedCubit
, you can use the ReplayMixin
.
class CounterCubit extends HydratedCubit<int> with ReplayMixin<int> {
CounterCubit() : 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};
}
Dart Versions #
- Dart 2: >= 2.7.0
Maintainers #
Starware #
ReplayCubit is Starware.
This means you're free to use the project, as long as you star its GitHub repository.
Your appreciation makes us grow and glow up. ⭐