replay_cubit 0.3.0-dev.1 copy "replay_cubit: ^0.3.0-dev.1" to clipboard
replay_cubit: ^0.3.0-dev.1 copied to clipboard

discontinuedreplaced by: replay_bloc
outdated

An extension to the cubit state management library which adds support for undo and redo.

Cubit

Pub build coverage Star on GitHub Discord License: MIT Starware

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 #

Supporters #

Very Good Ventures

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. ⭐

11
likes
40
pub points
46%
popularity

Publisher

verified publisherbloc-dev.com

An extension to the cubit state management library which adds support for undo and redo.

Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

cubit

More

Packages that depend on replay_cubit