Skip to content

When fetched data length is less than page size, widget loads duplicated for same offset #39

@onursahindur

Description

@onursahindur

First of all, appreciate for a great work. However I encountered a problem.
When the fetched data length from backend is less than the page size, for example data length for page 1 is 5 and page size is 25,
Widget loads the same page again.

Here is the code block I used for achieving the pagination.

body: SafeArea(
        child: PaginationView<Purchase>(
          paginationViewType: PaginationViewType.listView,
          itemBuilder: (BuildContext context, Purchase history, int index) => listItem(context, history, index),
          pageFetch: fetchSearchHistory,
          shrinkWrap: true,
          pullToRefresh: true,
          onError: (dynamic error) => Container(
              height: 70,
              alignment: Alignment.center,
              child: Text('Some error occured.', style: TextStyle(
                color: Colors.black,
                fontSize: 20,
                fontWeight: FontWeight.w400,
              )),
          ),
          onEmpty: Container(
              height: 70,
              alignment: Alignment.center,
              child: Text('No past searches', style: TextStyle(
                color: Colors.black,
                fontSize: 20,
                fontWeight: FontWeight.w400,
              )),
          ),
          bottomLoader: Center(
            child: CircularProgressIndicator(),
          ),
          initialLoader: Container(
              height: 70,
              alignment: Alignment.center,
              child: CircularProgressIndicator(),
          ),
        ),
      )

And the page pageFetch method is:

Future<List<Purchase>> fetchSearchHistory(offset) async {
    var page = (offset / 25).round() + 1;
    print(page);
    try {
      return await ApiServices.purchaseHistory(page);
    } catch (error) {
      print(error);
      return [];
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions