Hi Felix, I am using your bloc library for the first time in a project. Basically it's an app that mimics the search bar in Firefox next to the address bar (where it was possible to install multiple search engines). I have the following problem, I hope it's understandable without code:
Situation
Problem
Assumption
I solved this in a way which I do not like too much:
Is there a better solution to this or a pattern that I am missing?
Or can this be automatically taken care of by the bloc library?
Hi @ben-lotze !
It's always harder to tell what's going on without a sample app. To me it sounds like you are not yielding a new list of engines. Basically the bloc will compare the previous state with the current state and if they're equal it won't emit that last state. You're either misusing equatable or most likely you're not yielding a new list of engines; you should avoid altering the existing one and just create a brand new list of engines before yielding your new loaded state.
If my suggestion doesn't solve your issue then feel free to share a sample app and we'll have a look at it!
Hi @ben-lotze 馃憢
Thanks for opening an issue!
Are you able to share a link to a sample app which reproduces the issue? As @RollyPeres mentioned, it'll be much easier to help pinpoint the issue and suggest a fix.
Hi @felangel and @RollyPeres I uploaded the app code to github: https://github.com/ben-lotze/search_buddy
I'll try to explaiin as detailled as possible where the relevant code locations are, to not waste your time.
case 1, works as expected:
case 2 (should be the same as case 1, but it behaves differently)
_solution 1 (broken)_
_solution 2 (broken)_
_Tweak (broken)_
For testing purposes I added a refresh button into the drawer. It just fires a GetAllEnginesEvent which works as expected and refreshes the list of installed search engines.
_solution 3 (works, currently inactive and uncommented)_
Since refreshing works (at least sometimes?) when the event is fired when staring at the drawer, I use a callback method, that is executed after returning to the MainSearchRoute from the InstallEngineScreen.
the two relevant code locations are:
@ben-lotze I wasn't able to run your code on my machine, there's androidx issues. Mind upgrading your project to be androidx compatible?
@RollyPeres Oh, sorry, I updated the project to AndroidX. Hope it works now.
And thanks so much for your time!
Thanks for updating @ben-lotze , it runs now, however I keep getting Invalid argument(s): Record key cannot be null
Is it possible to create a minimal sample reproducing your issue ? Would help pinpointing the issue if you clean up all the unrelated dependencies so we can focus on the bloc related aspects without bumping into external factors.
@RollyPeres @felangel
Ok, this is a bit embarrassing. While coding the simplified example I realized the error in the app I linked above:
So, this is to potential later readers. Please correct me if I got this wrong. What happed was this:
So, problem solved. Sorry for the inconvenience. But a thousand thanks anyway.
Otherwise I would not have started an unfinished mini example that opened my eyes.
And it's just great how you guys are helping out here when problems occur. Keep up the great work.
@ben-lotze glad you found the solution yourself!
From having a quick peak at your app earlier, I'd suggest not manually creating blocs in initState and disposing yourself, you can leave that up to the BlocProvider to take care of.
So basically you can create a bloc directly in the build around the lines of:
BlocProvider(create: (_) => SearchBloc(someRepository: context.repository<SomeRepository>()))
Good luck with your project and feel free to come back if you encounter additional issues. 馃憤
@RollyPeres Thanks for the tip, that slims down the code and reduces errors, although IntelliJ warns you anyway when leaving them open.
I'll close this now as the problem is resolved.
Most helpful comment
@RollyPeres Thanks for the tip, that slims down the code and reduces errors, although IntelliJ warns you anyway when leaving them open.
I'll close this now as the problem is resolved.