Skip to content

Commit

Permalink
fix the same bug in infinite query observer
Browse files Browse the repository at this point in the history
  • Loading branch information
41y08h committed Jun 3, 2024
1 parent 2e80298 commit fa8f2a1
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions lib/src/infinite_query_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:fquery/fquery.dart';
import 'package:fquery/src/query.dart';
import 'package:fquery/src/retry_resolver.dart';
Expand Down Expand Up @@ -81,26 +82,28 @@ class InfiniteQueryObserver<TData, TError, TPageParam> extends ChangeNotifier
final isInvalidated = query.state.isInvalidated;

// [RefetchOnMount] behavior is specified here
if (isRefetching && !isInvalidated) {
switch (options.refetchOnMount) {
case RefetchOnMount.always:
refetch();
break;
case RefetchOnMount.stale:
DateTime? staleAt =
query.state.dataUpdatedAt?.add(options.staleDuration);
final isStale = staleAt?.isBefore(DateTime.now()) ?? true;
if (isStale) refetch();
break;
case RefetchOnMount.never:
break;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (isRefetching && !isInvalidated) {
switch (options.refetchOnMount) {
case RefetchOnMount.always:
refetch();
break;
case RefetchOnMount.stale:
DateTime? staleAt =
query.state.dataUpdatedAt?.add(options.staleDuration);
final isStale = staleAt?.isBefore(DateTime.now()) ?? true;
if (isStale) refetch();
break;
case RefetchOnMount.never:
break;
}
} else {
fetch(
options.initialPageParam,
FetchMeta(direction: FetchDirection.forward),
);
}
} else {
fetch(
options.initialPageParam,
FetchMeta(direction: FetchDirection.forward),
);
}
});
}

/// Takes a [UseInfiniteQueryOptions] and sets the [options] field.
Expand Down

0 comments on commit fa8f2a1

Please sign in to comment.