Skip to content

feat(ReplayBloc): allow user to choose which event or state change to be captured in the changeStack or not #4560

@ManuelRauber

Description

@ManuelRauber

This is a re-opening of #4178.

My use case is the following:

I have an Artboard Editor (like any image manipulation app like Photoshop), on this Artboard there are several layers that the user can move around.
Those layers are saved in a class managed by a bloc.

Now, since I have multiple other widgets that need to react on changes to the layers, the bloc is responsible of the handling of the user dragging/resizing the layers around.

I have multiple states and events for that:

final class EditorStateBase extends Equatable {
  final List<Layer> layers;
  // Cut for brevity.
}

// Default Editor editor when its ready to do something.
final class EditorState extends EditorStateBase {
  // Cut for brevity.
}

// Emitted as long as the user is dragging a layer, this happens as often as Flutter invokes the callback for GestureDetector.onPanUpdate.
final class EditorDragging extends EditorStateBase {
  // Cut for brevity.
}

// Same as EditorDragging, but for resizing.
final class EditorResizing extends EditorStateBase {
  // Cut for brevity.
}

As you can imagine, that dragging/resizing generates a lot of events, that I do not want to capture.
After a drag/resize is finished, the bloc emits the EditorState again.

It would be nice if we can specify that I only want to capture the emit of EditorState.

So in addition to shouldReplay, I'd like to have an shouldCapture:

class EditorBloc extends ReplayBloc {
  @override 
  bool shouldCapture(State state) => state is EditorState;
}

// ReplayMixin
bool shouldCapture(State state) => true;

@override
void emit(State state) {
  if (!shouldCapture) {
    return;
  } 

  // Original code
}

Alternaives

There are two alternatives:

  1. Implement a second bloc to manage the drag/resize and use a BlocListener to propagate the final change into the other bloc.
  2. Implement a StatefulWidget to handle drag/resize, propage the final change into the bloc and use an InheritedWidget to propage the intermediate changes to other widgets to let them react while the user is dragging/resizing.

Both seems to be more overhead to me instead of having a simple shouldCapture within the ReplayBloc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement candidateCandidate for enhancement but additional research is neededpkg:replay_blocThis issue is related to the replay_bloc package

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions