Comments (4)
Closing this for now since it sounds like the issue was resolved. Feel free to comment with additional questions/thoughts if that's not the case and happy to continue the conversation 👍
from bloc.
Hey!
First of all, I think it's worth taking a moment to think on whether filtering should be managed by your Blocs or by the Presentation layer. This is a good resource on that.
With that out of the way, you can probably store that variable in your state. I notice that you already store asksToDisplay
in your state, so perhaps you could also store answeredAsks
or something similar. You could also store only answeredAsks
and a filter
variable that can be used to dynamically determine which asks to display.
Does this help? Am I understanding the situation correctly?
from bloc.
@ksyro98 You are understanding correctly! I really really appreciate the response.
You make a good point about where the filtering should take place.
My understanding was that all logic for what the UI displays should be in the Bloc, which is why I was trying to do it there. Is that not the right move?
Should I not be having the value of asksToDisplay in my state and instead just have the BlocBuilder rebuild and the filtering is done inside the builder?
Storing answeredAsks in the state from the AnsweredAsksRepo stream would work, but then I have the value of answeredAsks in two different blocs, which is fine if they're both synced up, but there's no clear source of truth this way since I could change the value of answeredAsks in the CategoryBloc which wouldn't effect the answeredAsks in the repo.
Do my concerns make any sense?
from bloc.
Hey @DanMossa! Yes they make sense!
In my experience, there isn't a hard rule on whether all of the logic for the UI needs to be in a Bloc. It depends on the architecture you use.
What I see most often is that not all of the logic for the UI has to be in a Bloc. Specifically, UI logic can stay in the widgets, while business logic can be in the blocs. Which is more or less equivalent to saying "manage ephemeral state in widgets and app state in Blocs".
It's worth noting that logic which includes BuildContext
(e.g. localization logic or navigation logic) should never be in the Blocs, because Blocs are framework independent (the framework being Flutter).
For your case both approaches are valid, which is why I didn't recommend anything in particular in my previous response. I would personally manage filtering in the widget classes, and hold all of the items in the Bloc, but this isn't a hard rule, it's more of a personal preference. (Or there might be a rule I'm not aware of.)
You are correct that if you also store the state in the Blocs you might end up without a single source of truth. Good point!
Since you're using a behavior stream could you maybe get the answeredAsks
by getting the stream's last value?
Otherwise which is currently your single source of truth and can the CategoryAsksBloc
access it?
from bloc.
Related Issues (20)
- fix: Bloc Consumer's listener is passing the previous instance of the bloc to the method HOT 2
- fix: Bloc with searchAnchor Widget HOT 3
- fix: emitting a state in a closed Cubit throws an error HOT 5
- Unable to upgrade to 4.0.0 Bloc plugin on Intellij HOT 5
- perf: Example of not duplicating data with repository pattern in todos example HOT 4
- question: I need to access the latest state of bloc outside of a widget tree in a helper function. HOT 5
- Emit that occurs during init doesn't cause a rebuild HOT 1
- question: is this considered a anti pattern if a repository depends on another bloc. HOT 2
- docs: RTL in documentation
- feat: allow user to choose which event or state change to be captured in the changeStack or not HOT 2
- feat: Translation of menu and prev, next, note title in the document HOT 1
- question: UI interactivity and separation of concerns HOT 2
- question: Having a bloc inherit from a another bloc HOT 1
- style: Move the "props" getter to the parent (sealed) class HOT 1
- fix: How to listen to multiple streams in a single event? HOT 1
- feat: can we rename copyWith to replaceWith HOT 1
- fix: com.bloc.intellij_generator_plugin.action.GenerateBlocAction retains disposed Project HOT 3
- feat: Enhance BlocBuilder with Dependencies for Selective State Changes HOT 1
- [help] Best Practice for Sharing Events and States Across Multiple Blocs, Bloc to Bloc communications HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bloc.