What is the correct way of massing multiple variable arguments to a riverpod provider #3517
Replies: 2 comments 2 replies
-
You could create an AllProducts provider that fetches all your product (using the code of your current provider, but with no parameter) and then have the provider FetchProducts with the parameters depending on AllProducts and filtering using the parameters. |
Beta Was this translation helpful? Give feedback.
-
Here is full console output on first run of this app widget. Note that it prints twice with same number of items in the products list and hash value of provider is same (I'm using ProviderObserver class to print provider updates as per riverpod docs).
// After choosing a client from DropDownMenu
|
Beta Was this translation helpful? Give feedback.
-
I am passing arguments to my provider like
As soon as my UI page opens all products are fetched by a widget with both specificProductId and clientUid as null/empty.
final productList = ref.watch(fetchProductsProvider(clientUid: null, specificProductId: null));
There is another notifier provider which gives clientUid when a client is chosen in UI. This triggers a widget on the same UI page to fetch products for that specific clientUid.
ref.watch(FetchProductsProvider(specificProductId: null, clientUid: widget.clientUid));
However, this causes the provider with all the products i.e.
productList
getting disposed off.Problem: How to keep the state of the provider with all the products intact when provider is watched by any other widget with different set of parameters, but auto-disposing the provider when the last listener has been removed?
Current Console output looks like -
Beta Was this translation helpful? Give feedback.
All reactions