I've been using flutter blocs for a while and I have a problem which I don't know what would be the best approach to solve it.
I have a Widget that uses a bloc. This widget has an input text field and a button which fires a network request calling bloc.sendRequest(text)
. The bloc emits a ResponseState(bool success, string message)
depending on the server response. If there is an error the bloc builder will show a pop up displaying the error message and asking the user to change the input field.
The problem comes when the user press the text input after the error pop up is shown. Flutter refresh the builder bloc and the used state is the previous one, which it cointains the error message that has been already shown, causing the builder to show again the pop up. What should be the best approach to tackle this situation? I've thought about some solutions:
- Add a timestamp to the
ResponseState
and do not rebuild the builder if the state is the same as before. - Make the
bloc.sendRequest(text)
call return the result and show the pop up if required once theFuture
is completed - Track which pop ups have been showed to avoid showing them twice using a timestamp in the
ResponseState
What should be the best approach to solve this? I'm missing something?
Thanks,