You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Imagine that you are using the same widget to render a list of items, but you want to apply one filter to the list, so that it refetches again the items, but with the updated query. In my case the filters (and pagination) are treated in the firstPageKey.
The problem resides in that when I rebuild the widget passing another filters to the firstPageKey, since the StateNotifierProvider is already alive, it does not update its values, since they are declared once when building the initial state (on super constructor). How we could be the best way to solve this problem? Refreshing the provider?
The text was updated successfully, but these errors were encountered:
hey @francescreig what about the filterData() method inside the StateNotifier. i mean you can invoke filterData() method when applying a filter and then updating the state of your notifier accordingly. something like this
void filterData() async {
try {
// filter your data here
//final response = filterDataMethod(); /*make an api call to receive data*/
state = state.copyWith(
records: [
...response,
// ...(state.records ?? []),
],
nextPageKey: response.length < limit
? null
: response[response.length - 1].id,
previousPageKeys: {
...state.previousPageKeys,
page,
}.toList());
} catch (e) {
logger.e(e.toString());
}
state = state.copyWith(
records: [],
nextPageKey: [],
previousPageKeys: [],
);
}
Although i am also not an expert but i think it might work for you.
Hi @francescreig maybe you could use a family provider where the family is represented by the filters? Or else you can manually invalidate the provider using ref.refresh / ref.invalidate
Imagine that you are using the same widget to render a list of items, but you want to apply one filter to the list, so that it refetches again the items, but with the updated query. In my case the filters (and pagination) are treated in the
firstPageKey
.The problem resides in that when I rebuild the widget passing another filters to the
firstPageKey
, since the StateNotifierProvider is already alive, it does not update its values, since they are declared once when building the initial state (onsuper
constructor). How we could be the best way to solve this problem? Refreshing the provider?The text was updated successfully, but these errors were encountered: