reversible_bloc 0.0.1 copy "reversible_bloc: ^0.0.1" to clipboard
reversible_bloc: ^0.0.1 copied to clipboard

A bloc mixin that enables to rollback states.

codecov Version GitHub license

A Bloc mixin that enables to revert the bloc / cubit to a previous state.

Usage #

To use reversible_bloc, you need to import and mix ReversibleBlocMixin to your Bloc or Cubit.

class MyReversibleCubit extends Cubit<int> with ReversibleBlocMixin {
  MyReversibleCubit(int initialState) : super(initialState);

  void changeValue(int newValue) => emit(newValue);
}

Then, when you need to rollback to previous state, you can use revert() method.

final myReversibleCubit = context.read<MyReversibleCubit>();
myReversibleCubit.changeValue(2);
myReversibleCubit.changeValue(4);
// Current state is 4
myReversibleCubit.revert();
// Current state back to 2
myReversibleCubit.revert();
// Current state back to initial state
myReversibleCubit.revert();
// throws EmptyStackException

How to contribute #

Feel free to add sugestions and report bugs in Issues page. PRs are welcomed too.

Maintainers #

7
likes
150
points
36
downloads

Publisher

unverified uploader

Weekly Downloads

A bloc mixin that enables to rollback states.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bloc, flutter

More

Packages that depend on reversible_bloc