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

Viewed 24

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),
                ),
              ),
0 Answers
Related