-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add an event parameter in BlocListener #4346
Comments
That's exactly what I'm doing and would love this as well. Would help solve #4342 |
Hi @babakoto 👋 Rather than exposing event information to the BlocListener API, I highly recommend revisiting your state model. The state model should contain all relevant information needed for the presentation layer to function. If you really need to differentiate between the root cause for a property to have changed, you should consider adding more information/restructuring your state. I can’t provide a concrete suggestion without additional context but hope that helps 👍 If you’re still having trouble, please share additional context and explain what specifically you’re trying to achieve and I’m more than happy to provide suggestions/code snippets. |
@felangel |
Not sure what you mean. The UI is responsible for notifying the bloc of events and re-rendering in response to states. How you model the states is totally up to you and depends on the feature you’re building. |
If the Context: Authentication ManagementI use I have an AuthBloC that handles multiple actions: sign-in, sign-up, and password reset. These actions can coexist on the same page, for example, in a Form ManagementMy BloCs do not directly manage forms; they only receive a Issue FacedWhen displaying a How can I accurately identify which action was successful in the Current SolutionThe solution I’m using is adding an if (state.query.isSuccess && state.event is OnSignInEvent) {
// Handle sign-in success
}
if (state.query.isSuccess && state.event is OnSignUpEvent) {
// Handle sign-up success
} |
Thanks to all the contributors!
I would like to know if it’s possible to add an event in the BlocListener parameter.
Let’s say my state contains 3 fields like this:
Let’s assume
EventA
modifies only thea
field, andEventB
modifies botha
andc
.I want to know which event modified the a field in my state, using a BlocListener like this:
Currently, the solution I’m using is to store the event in the state itself:
The problem with BlocObserver is that it doesn’t have access to the Flutter context, which doesn’t solve my issue.
The text was updated successfully, but these errors were encountered: