cached_query icon indicating copy to clipboard operation
cached_query copied to clipboard

feat: invalidateQueryAndRefetchIfListeners()

Open iOSonntag opened this issue 9 months ago • 3 comments

First of all great work!

Regarding my issue, I searched ages and dived deep into the framework code on how to be able to invalidate a query and only refetch it, if it actually is used somewhere. Turns out its not possible out of the box so I wrote myself an extension:

extension ExtensionOnQueryBase<T, State extends QueryState<dynamic>> on QueryBase<T, State> {

  void invalidateQueryAndRefetchIfListeners()
  {
    invalidateQuery();

    if (hasListener) refetch();
  }
}

I know the name is not the best, but explaining people that this is what you want regarding not asking the server to much and still having a nice user experience and it is not shipped within the docs or the framework might be an issue for many people beeing guided in the wrong driection IMO

iOSonntag avatar May 10 '24 00:05 iOSonntag