-
-
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
BlocBuilder with Optional Build Condition #315
Comments
Yeah. Like the rebuild on change feature. Sure. This is also an alternative to putting a where condition on a stream to filter each event. I used to do this right in my StreamBuilder. StreamBuilder(
stream: myStream.where((transition) =>
transition.oldState != transition.newState),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return Container();
},
) To build the where into the backend of the BlocBuilder widget and drop any conditions into it with a default function return true. I think that would be the simplest solution. I think the |
I think there's a few things to consider here before making a final decision:
There could be other ways to solve this, like introducing just a I'll try to think about it more over the weekend |
@jorgecoca previous state would always be last emitted. For tracking last rendered, the builder can implement |
@jorgecoca thanks for the feedback here's what I'm thinking:
I considered a separate widget but I really like the fact that there's just a single widget used to render UI in response to state changes. I also agree that this can be accomplished using multiple blocs but it's not as intuitive and easy to manage imo. Definitely think about it over the weekend 👍 |
Seems good ! 👌
and this way we also avoid breaking changes, right ? I guess it will be also implemented for the |
@felangel the suggestion sounds good to me. I think it makes sense; I just wanted to bring those points to our attention, so we do not oversee them. I think there might be value, though, in tracking/logging when a What do you think? PS. And now thinking about this, and given the history of issues that some other devs have opened in the past, I wonder if this kind of extra logging should be added when the bloc does not emit a state because |
Also, in case we would want to leave this API for experimentation/trial period, we could use the https://pub.dev/documentation/meta/latest/meta/experimental-constant.html |
@jorgecoca how would the bloc know? He would have to wire in a message back to it when the rebuild is ignored. If it's anything like the principle of simply notify listeners and let them do what they want with the information, where the sender is not concerned with what the reciever does with the information, then it's not the bloc's job to log that. |
@axellebot the condition would default to always return condition: (previous, current) => true The case you're describing is already handled by the bloc itself. PR is open (#319) |
This feature is now available in flutter_bloc v0.15.0 🎉 |
On my side, no matter whether the value of |
@Hentioe can you provide a sample app which reproduces the issue you're facing? Thanks! |
The |
note, that it is called buildWhen and not condition since 5.0.0 |
Is your feature request related to a problem? Please describe.
Proposal to address #174
Describe the solution you'd like
Proposing to add an optional
condition
property toBlocBuilder
which takes thepreviousState
andcurrentState
as arguments and must return abool
which determines whether or not to rebuild.Usage
In the above example, the
Text
widget with the remaining time will be rebuilt every time a new state is received (every second) whereas theActions
widget will only be rebuilt if the stateruntimeType
changes (Ready
->Running
,Running
->Paused
, etc...).Describe alternatives you've considered
Lots of alternatives described in #174.
The text was updated successfully, but these errors were encountered: