Parallel Event call
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
Hi @visual-velocity 👋 Thanks for opening an issue!
Can you please provide a link to a sample app which illustrates the issue? Thanks 👍
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 .
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.
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.
Closing this for now but feel free to comment with additional information or a sample app and I'm happy to continue the conversation 👍
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
mediaAttachmentCreatedcall. - User can submit a message via
messageSubmittedcall, 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
createAttachmentApifuture 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
createAttachmentApito be finished. May I know how it can be fixed?