skip to Main Content

I have flutter solution, I’m working in pagination in my listView…
When existing list is equal to totalRecords I call refreshController.loadNoData() to stop paginating.

Unfortunatly, in my case listLength is equal to 10 anf totalRecords is 23 but this comparision is returning true and my pagination is not wokring because this error in comparision.

Did have have something ?

if (10 == 23) 

should return false in my case but it is returning true.

int listLength = requestList.value.data!.length;
int totalRecords = value.totalRecords!;
if (listLength == totalRecords) {
refresherController.loadNoData();
}

2

Answers


  1. Try printing the values first, then check if they’re the same:

    debugPrint(requestList.value.data!.length.toString());
    debugPrint(value.totalRecords!.toString());
    

    Normally, these should be different, because there is no way that it returns true otherwise.

    Login or Signup to reply.
  2. int listLength = requestList.value.data!.length;
    int totalRecords = value.totalRecords!;
    
    if (listLength >= totalRecords) {
      refresherController.loadNoData();
    }
    

    I changed the equality comparison (==) to a greater than or equal to comparison (>=). This change will ensure that refresherController.loadNoData() is called when the listLength is equal to or greater than totalRecords. By using >=, the pagination will stop when the length of the list exceeds or matches the total number of records.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search