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
Filtering Consumer updates #26
Comments
How would that be implemented? From my understanding there's no way for widgets to cancel a rebuild |
I'm going to close this, as it's not doable. Not only do widgets cannot cancel a rebuild, but there's also a bigger flaw: In 99% of the situations with |
@rrousselGit I also need this.
for best performance,I don't think it need to rebuild the entire screen and also I don't want to write a ChangeNotifier for every property.I just need write a ChangeNotifier with many properties. |
@aloisdeniel do you have any ideas? |
That's simply not possible with mutable objects like |
@rrousselGit can you provide me some examples?and your example is too simple.sorry. i'm confused |
I think you can save last value,like Int ,String value. |
From a discussion on gitter: Most of the time, the worry you have is just premature optimisation. But if you really need that optimisation, you can ProxyProvider class ManyMutableThings with ChangeNotifier {
String foo;
int bar;
}
class ImmutableCopyOfTheFewFieldsYouNeed {
ImmutableCopyOfTheFewFieldsYouNeed({this.foo});
final String foo;
}
Widget build(BuildContext context) {
return ProxyProvider<ManyMutableThings, ImmutableCopyOfTheFewFieldsYouNeed>(
builder: (_, model, __) => ImmutableCopyOfTheFewFieldsYouNeed(foo: model.foo);
updateShouldNotify: (a, b) => a.foo == b.foo,
child: Consumer<ImmutableCopyOfTheFewFieldsYouNeed>(
builder: (_, data) {
return Text(data.foo);
},
);
} |
Having a way to filter updates at the consumer level may be useful to fine-grain builds.
For example, if we have a
ChangeNotifier
model with multiples properties,notifyListeners
would be called each time a value of a property changed. If we have aConsumer
for that model that only depends on one of the properties, it is updated even when an other property changes.We could have a
bool shouldBuild(T previousValue, T newValue)
argument forConsumer
for that purpose.The text was updated successfully, but these errors were encountered: