fl-query
fl-query copied to clipboard
QueryClient.invalidateQueries([...])
For my project, this would be more useful than refetchQueries, as I don't want to be loading too much stuff in the background.
I think what you want to achieve is invalidateQueries? You want to just make them stale but don't want the queries to refresh immediately and only refresh when required?
Yes, exactly
I've solved it with an extension. Let me know if it makes sense to you to include in the library. @KRTirtho
extension FLQueryClient on QueryClient {
void invalidateWithPrefix(String prefix) {
final queries = getQueriesWithPrefix(prefix);
for (var query in queries) {
query.reset();
if (query.hasListeners) {
query.refresh();
}
}
}
}
Yeah actually it was planned already. But never made it in a release.
But what you're suggesting, has query.refresh so it doesn't actually make any difference that refreshWithPrefix
Are you sure it does not make any difference?
I've had a lot of queries and calling refreshWithPrefix had refreshed even the inactive ones, resulting in 429 errors and unnecessary server load.
My implementation seems to correctly mark the queries for reload only after user visits their page.
Ok, so I guess because of the hasListeners it'll update the UI only when it's mounted otherwise it'll be resetted.
We can add it ✅