Is it a good practice (or at least possible) to trigger an event during a state change in flutter with flutter_bloc? As in:
if (state is SomeState) {
_bloc.add(Event())
}
My use case in this scenario is to trigger a modal as reaction to some state change, however everytime I do this (tried with BlocListener and BlocBuilder) the modal is always triggered twice, as in you have to close 2 modals.
I have to do this because I do 2 api calls, each event triggering one call PostEvent and GetEvent let's say, and I want the modal to open only after the second one is finished.
PostEvent -> Request -> StateChange -> Builder -> add(GetEvent) -> Request -> StateChange -> Builder -> showModal()
I was also wondering if I should do both calls in the same method but haven't tested that yet.
After doing some digging I found that that even though the Event was only added once, the Widget was rebuilding 2 times with the same state (GetFinished e.g) therefore showing the 2 modals.
Any help would be appreciated.
Thanks