Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh calls ignored when other refresh in progress #338

Open
prokyhb opened this issue Aug 3, 2024 · 3 comments
Open

Refresh calls ignored when other refresh in progress #338

prokyhb opened this issue Aug 3, 2024 · 3 comments

Comments

@prokyhb
Copy link

prokyhb commented Aug 3, 2024

Hello,

I need to be able to refresh page (after filtering) quite frequently (using barcode scanner), but once one "refresh" is in progress and I execute another one, the 2nd gets ignored.

I've tried several approaches like using buffer listener (triggering another refresh after complete status, but refresh is not triggered in listener at all) and another techniques, but with no luck.

Is there any option how to cancel current refresh operation and trigger new one?

Thank you.

@Bertus-W
Copy link

was looking for this as well. I saw a thing on the paging controller called controller.value.status which is of the type PagingStatus but that status never seems to change either.

@ShankarKakumani
Copy link

I also have this issue now. Not sure how to solve it.
had to move away from library because of this issue.

@r-i-c-o
Copy link

r-i-c-o commented Oct 18, 2024

I have found a pretty minimalistic way to fix this issue. The root of this problem is that PagingController can't tell the difference between subsequent refreshed states, because they are all equal to each other and are filtered out by ValueNotifier superclass. So we can simply assign some tag (int in my case) in PagingState subclass to guarantee distinction between states after refresh(). Now we can use VersionedPagingController everywhere without additional refactor.

///Implementation of [PagingController] that supports distinction between refreshes
class VersionedPagingController<PageKeyType, ItemType> extends PagingController<PageKeyType, ItemType> {
  VersionedPagingController({required PageKeyType firstPageKey})
      : super.fromValue(
          VersionedPagingState<PageKeyType, ItemType>(version: 0, nextPageKey: firstPageKey),
          firstPageKey: firstPageKey,
        );

  int _currentStateVersion = 0;

  int get currentStateVersion => _currentStateVersion;

  @override
  set value(PagingState<PageKeyType, ItemType> newValue) {
    final versionedState = VersionedPagingState(
      version: _currentStateVersion,
      nextPageKey: newValue.nextPageKey,
      itemList: newValue.itemList,
      error: newValue.error,
    );
    super.value = versionedState;
  }


  @override
  void refresh() {
    _currentStateVersion += 1;
    super.refresh();
  }
}

class VersionedPagingState<PageKeyType, ItemType> extends PagingState<PageKeyType, ItemType> {
  const VersionedPagingState({
    super.nextPageKey,
    super.itemList,
    super.error,
    required this.version,
  });

  final int version;

  @override
  String toString() => 'VersionedPagingState (itemList: $itemList, error: $error, nextPageKey: $nextPageKey, version: $version)';

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) {
      return true;
    }
    return other is VersionedPagingState &&
        other.itemList == itemList &&
        other.error == error &&
        other.nextPageKey == nextPageKey &&
        other.version == version;
  }

  @override
  int get hashCode => Object.hash(
        itemList.hashCode,
        error.hashCode,
        nextPageKey.hashCode,
        version.hashCode,
      );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants