Currently, the only way of notifying the page of state changes is by yielding a new state. However, there are a lot of instances where I want to do something outside of the build method (Run only once) without changing my state.
Would it be okay to pass a function as a parameter in an Event and inside of the Bloc, run that function after doing something?
For a more specific example, I have data in my ApplicationState that encompasses my whole application. After doing some actions on various pages, my Blocs make API calls to a service and I want to update the data in my ApplicationState in various places throughout my app with the data that I get from the service. I don't feel like the best way to do this is by yielding a new state and I don't know if passing the ApplicationBloc in my Event is good either.
@QoLTech thanks for the question!
Technically you can do that but I wouldn't really recommend it. I'm curious to understand why you are saying you don't believe yielding a new state is the best way to change the application state? I would argue that is the correct way to achieve what you're asking. Can you provide some more details?
Thanks! 馃憤
Well, for example, I need to update something on my server.
I don't want to change the state of my page after the update is basically what I'm held up on because nothing on my page needs to change. My page state is exactly what I want it to be.
Does this make sense? I just don't have a need to update my current page state in this process and updating my state basically as a trigger to run a function and then change it back seems unnecessary.
@QoLTech I think I understand what you're trying to do now. Thanks for the extra details 馃憤
I think you don't have to always think of blocs as tying into the UI layer directly. In this case, it might makes sense to have a new bloc for managing the event after the server responds with the data you need. Then, the flow could look something like:
Let me know if that helps! 馃憤
Okay, I see. So, should I pass in BlocB as a parameter in the Event in step 1? This seems like a better idea, I just wasn't sure if I should have Blocs depend on each other.
I would not need to yield an UpdateState in step 4. I would only need to yield the original state - I don't even need the data back in this page.
I wouldn鈥檛 pass it over the event. I鈥檇 recommend injecting BlocB into BlocA via constructor.
You can see an example of this in the todo tutorial.
Out of curiosity, can you describe the functionality of your app and what this event is doing?
Closing for now but feel free to comment with more questions/details and we can continue the conversation. 馃憤
Most helpful comment
Closing for now but feel free to comment with more questions/details and we can continue the conversation. 馃憤