bloc
bloc copied to clipboard
feat: dryRedo on replay_bloc
I love bloc and cubit, but I'm fighting with a few limitations.
Imagine Cubit as the Navigation stack (back/forward button, etc). I wish I could do this:
- I am on screen A, move to screen B, go back to A. Move B to the trash. I can't "redo" to go to B because B is on the trash, so I would need to check like
trash.contains(dryRedo())
. I don't want to redo. I want to know if I can redo based on redo value without removing it from its stack. - Browser back-stack. You might want to see a preview of the previous/next page. Maybe even the full back history, in a list. The following image is not possible with cubit:
Possible Desired Solutions
- Something like dryRedo() / dryUndo() (maybe a better name?), that gets the value, but doesn't remove from the history.
- Making history and current index not private. So the user could do
history.range(index, history.length)
and get the forward redo history. - Make
List<T> undoValues(int? limit)
andList<T> redoValues(int? limit)
, soredoValues(1).first
would do what I want.
The last one is slightly more verbose but seems better. I also like the second one. If it were public inside the bloc, at least, I would be able to fix myself. Maybe with tuples it could be (int, ?) getHistoryIndex
.
Hello,
I'm currently coding a note-taking app where this functionality will also be useful.
The range function could be implemented using the take function: https://api.dart.dev/stable/3.0.0/dart-core/Iterable/take.html.
But currently, emit doesn't know on which event it was called: https://github.com/felangel/bloc/blob/master/packages/replay_bloc/lib/src/replay_cubit.dart#L67
Without this information, you couldn't add an undo history of a column like Adding stroke
or something else.