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

The refresh() method throws multiple queries when using the infinite_scroll_pagination package #221

Closed
atasumt opened this issue Sep 6, 2022 · 2 comments

Comments

@atasumt
Copy link

atasumt commented Sep 6, 2022

I am using the infinite_scroll_pagination package but i am having trouble. My problem is as follows: I have two different pages, one is a list of products, one is a list of filters, after going to the filter list and calling the controller.refresh() method, the package I use when returning is throwing multiple interrupt queries, while doing this, the number of times I enter the filter page, the more requests I get. . my code is below. Could you help?

`final PagingController<int, CompanyProductsDatum> pagingSellerPageController = PagingController(firstPageKey: 1);

  @override
  late Rx<Future<List<Object?>>> mainFuture = Future.wait([]).obs;

  @override
  void onInit() {
    // TODO: implement onInit
    updateMainFuture();
    super.onInit();
  }

@OverRide
void dispose() {
// TODO: implement dispose
super.dispose();
pagingSellerPageController.dispose();
}


  @override
  void updateMainFuture() {
    // TODO: implement updateMainFuture
    pagingSellerPageController.addPageRequestListener((pageKey) {
        sellerPageProduct(pageKey);
    });


    Future<void> sellerPageProduct(int page) async {
    filterCategoryIds.value.add('${tagButtonController.value}');
    try {
      final newItems = await sellerPageProductService(
        companyId: Get.parameters["id"].toString(),
        page: page.toString(),
        categoryIds: filterCategoriesKey.value.currentState?.fields['categories']?.value ?? filterCategoryIds.value,
        brandsIds: filterBrandsKey.value.currentState?.fields['brands']?.value,
        sortColumn: sortColumn(),
        minPriceProducts: minSale(),
        keyword: sellerPageSearchFormkey.value.currentState?.fields['sellerpagesearch']?.value ?? '',
      ).then((res) => sellerPageProductsData.value = res);
      final isLastPage = newItems.paginate!.page == newItems.paginate!.pages;
      if (isLastPage) {
        pagingSellerPageController.appendLastPage(newItems.companyProductsData ?? []);
      } else {
        final nextPageKey = page + 1;
        pagingSellerPageController.appendPage(newItems.companyProductsData ?? [], nextPageKey);
      }
      update(['sellerpageproducts']);
    } catch (error) {
      pagingSellerPageController.error = 'Errorrr';
    }
  }


   GlobalElevatedButton(
                height: 36,
                width: context.width * 0.3,
                onPressed: () async {
                  controller.pagingSellerPageController.refresh();
                 
                  await Get.offNamed('/sellerPage/?id=${Get.parameters["id"].toString()}');
                },
                text: 'Filtrele',
                textStyle: Theme.of(context).textTheme.subtitle2!.copyWith(
                      color: kBgColor,
                      fontSize: 12,
                    ),
                style: ButtonStyle(
                  shape: MaterialStateProperty.all<OutlinedBorder>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(30))),
                  backgroundColor: MaterialStateProperty.all<Color>(kPrimaryColor),
                ),
              ),`
@samtuga1
Copy link

samtuga1 commented Apr 2, 2023

I'm also facing a similar issue. Did you find any solutions yet?

@atasumt
Copy link
Author

atasumt commented Apr 11, 2023

I think the problem is reloading the page. I checked and edited my root structure. I avoided page reload using flutter_hooks

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

3 participants