bloc icon indicating copy to clipboard operation
bloc copied to clipboard

Parallel Event call

Open prasantco opened this issue 6 years ago • 6 comments

I have a screen and a bloc. With this bloc i'm calling three events sequentially. Each event returns a state but my screen was not updating by any state.How do i resolve this issue and update my screen by three state. @override Stream<Transition<DashboardEvent, DashboardState>> transformEvents(Stream events, transitionFn) { // TODO: implement transformEvents //return events.debounceTime(const Duration(milliseconds: 300)).switchMap(transitionFn); return events.flatMap(transitionFn); }

prasantco avatar Aug 23 '20 17:08 prasantco

Hi @visual-velocity 👋 Thanks for opening an issue!

Can you please provide a link to a sample app which illustrates the issue? Thanks 👍

felangel avatar Aug 24 '20 03:08 felangel

Sure

On Mon, 24 Aug, 2020, 9:21 am Felix Angelov, [email protected] wrote:

Hi @visual-velocity https://github.com/visual-velocity 👋 Thanks for opening an issue!

Can you please provide a link to a sample app which illustrates the issue? Thanks 👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/felangel/bloc/issues/1663#issuecomment-678889284, or unsubscribe https://github.com/notifications/unsubscribe-auth/APGW34VXXH6LSOSCMFOA5LDSCHPT5ANCNFSM4QIY5FUA .

prasantco avatar Aug 24 '20 04:08 prasantco

I have simple issue I have a Dashboard BLoC and it's have three events. I want to call three apis from three events along with return respective states. I have also three widgets and it's update value from the three states. @felangel can you give us some suggestion for solve this issue.

prasantco avatar Aug 24 '20 13:08 prasantco

What's the issue? You can call three APIs in response to the events and use copyWith to add the relevant data to your state.

felangel avatar Aug 24 '20 15:08 felangel

Closing this for now but feel free to comment with additional information or a sample app and I'm happy to continue the conversation 👍

felangel avatar Aug 26 '20 03:08 felangel

Hello @felangel,

I have similar question. My use case is like this, which is a chat app.

Below is a simplified code:

  • User can make an attachment via mediaAttachmentCreated call.
  • User can submit a message via messageSubmitted call, when it's called, a message will be inserted immediately before API returns, after API return, it will refresh that message again.
  @override
  Stream<CommentComposerState> mapEventToState(
    CommentComposerEvent event,
  ) async* {
    yield* event.map(
        mediaAttachmentCreated: (e) async* {
          /// User make an attachment
          yield state.copyWith(hasAttachmentInProgress: true);
          final result = await createAttachmentApi(xxxx);
          yield state.copyWith(attachment: result.token, hasAttachmentInProgress: false);
        },
        
        messageSubmitted: (e) async* {
          /// User submitted message from textfield, it will be used to update chat's list view
          yield state.copyWith(
            message: e.message,
          )
          
          await waitForAttachmentCreated();

          final result = await submitMessageApi(message, attachmentToken);
          
          /// Update list view again to refresh the message
          yield state.copyWith(xxxx);
        }
    );
  }

Now I have a problem like this:

  • User makes an attachment, and if the attachment is large or user has a slow network connection, it may take a few seconds to upload.
  • User submits a message before createAttachmentApi future finished.

→ If it is in that case, the chat list UI won't be updated immediately, it will be updated until createAttachmentApi has finished.

The ideal case is:

  • User attaches a file, submit a message, it will appear in the chat list ui immediately, in which it doesn't need to wait for createAttachmentApi to be finished. May I know how it can be fixed?

am5a03 avatar Oct 30 '20 11:10 am5a03