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
ProxyProviders in RiverPod #150
Comments
|
There's a WIP to allow something similar: final myNotifier = ChangeNotifierProvider<MyModel>((ref) {
final model = MyModel();
ref.listen<Value>(provider, (Value value) {
model.update(value);
});
return model;
}); |
|
Is this feature going to be released in the near future? |
|
Maybe after March You don't "need" this new feature. You can do it with slightly more code yourself: final anotherModel = ChangeNotifierProvider<Another>(...);
// obtains "Another" but will not cause dependent providers to "rebuild" when notifyListeners is called
final _anotherSelector = Provider((ref) => ref.watch(anotherModel));
final myNotifier = ChangeNotifierProvider<MyModel>((ref) {
final model = MyModel();
Another another = ref.watch(_anotherSelector);
void listener() {
model.update(another.value);
}
another.addListener(listener);
ref.onDispose(() => another.removeListener(listener));
return model;
});That does the same thing as shown before and works with nearly all use-cases. It's just less convenient. |
|
@rrousselGit would you also "recommend" that workaround for |
|
Yes, this is fine. |
|
@rrousselGit Why would you use watch and not read in the last example in the myNotifier _create method? |
|
Closing in favor of #335 for the |
I just recently migrated to Riverpod and I must say I'm liking it so far.
One thing i kind of miss from Provider is the following:
This creates a ChangeNotifier that has a reference of an other ChangeNotifier that gets updated through the update() method on the new ChangeNotifier. This means that the ChangeNotifier to be created, won't recompute when the referenced ChangeNotifier changes.
Atm i'm using this workaround for Riverpod:
In this example the secondProvider would have an instance field called firstModel that gets updated through the method updateFirstModel().
The text was updated successfully, but these errors were encountered: