Hi @felangel , i was stuck on this particular issue.In my last issue you recommended me to put a timeout for the users of my app in case the background fetching took too long.As it is mainly dependent on the API itself, i decided to login the user while some tasks continue running in the background (fetching additional user infos) which are then inserted into the sqlite DB.My UI must trigger a change when all this processing is done.I couldnt pass the bloc via BlocProvider.of as it is in my repository class that does the data fetching and storing, so i created a new instance, and dispatched an event when the insertion has been done.
The Delegate notices the transition but the different BlocBuilder do not.I managed to get the intended functionnality to work by passing around the first instance of my bloc...But i find this way of doing stuff too spaghetti...sorry for the broken english here.
Is there a more elegant way of achieving this without passing bloc instances to all my methods in classes that are not flutter related?
Hey @zjjt 馃憢
In general, you can get access to the bloc however you'd like (BlocProvider, manual dependency injection, using a DI framework like Kiwi etc...)
In this case, it sounds like an issue where BlocBuilder
is hooked up to the wrong bloc (maybe if you have multiple instances of the same bloc or some other funky issue). I'd have to take a look at some sample code in order to give you a definitive reason. Let me know if that helps otherwise please share a sample app with the problem you're having and I can take a look. Thanks 馃憤
Alright, as always thank for the quick answer. Ill go this route for now as i have to demo the app tomorrow.Ill post a link to the repo once i am done with it.Indeed the BlocBuilders are hooked up to the first instances which i created in the root widget of the app.I get access to those by using BlocProvider.of method in my widgets.But in my repository,i created new instances of those bloc as i couldnt get the context in my repository in the first place(i didnt want to pass context around)..that is why the Delegate did notice when an event occured but the top instances hooked to BlocBuilder did not.I resolved it by passing the top instances to my repository.Ill look into DI frameworks for those kind of situations.
Kiwi seems like the way to go to handle my use case.I thought yesterday of using a static class containing all instances of my blocs which i could reuse even in deep parts of my app which do not have access to widget context from flutter....Ill give kiwi a go