isFetching method
bool
isFetching({
- ZenQueryFilter? filter,
- Object? queryKey,
- String? tag,
- bool predicate(
- ZenQuery query
Returns whether queries are currently fetching.
Can optionally be filtered by:
filter: Matches queries using a ZenQueryFilter.queryKey: Checks if the specific query matching the key is currently fetching.tag: Checks if any query with the given tag is currently fetching.predicate: Checks if any query matching the custom predicate is currently fetching.
If no filters are provided, returns whether ANY query in the application is currently fetching (ZenQuery.anyFetching).
Implementation
bool isFetching({
ZenQueryFilter? filter,
Object? queryKey,
String? tag,
bool Function(ZenQuery query)? predicate,
}) {
if (filter != null) {
return _queries.values.any((q) => filter.matches(q) && q.isFetching);
}
if (queryKey != null) {
final normalizedKey = QueryKey.normalize(queryKey);
final query = _queries[normalizedKey];
return query != null && !query.isDisposed && query.isFetching;
}
if (tag != null) {
final queries = getQueriesByTag(tag);
return queries.any((q) => q.isFetching);
}
if (predicate != null) {
return _queries.values
.where((q) => !q.isDisposed)
.any((q) => predicate(q) && q.isFetching);
}
return ZenQuery.anyFetching;
}