The issue I am currently facing is when the screen is first opened the pagination works fine but when I go to another page and comeback to the page the count of the page is again processed and duplicate data is being shown.
Additionally on further checking the code it was found that the below line of code is running in loop :
if (_sc.position.pixels == _sc.position.maxScrollExtent)
And the print statement is called twice(please check below code)
If anyone can please help me resolve this issue.
Let me know if you require any further information from my end.
List.dart
@override
void initState() {
print('current page value init: ${currentPage}');
checkId = Provider.of<LoginProvider>(context, listen: false).id;
categoryCheck = Provider.of<LoginProvider>(context, listen: false).category;
if (categoryCheck != null) {
if (Provider.of<OpenProjectProvider>(context, listen: false)
.items
.isEmpty) {
myfuture = Provider.of<OpenProjectProvider>(context, listen: false)
.readinboxNotification(checkId, currentPage);
}
} else {
if (Provider.of<OpenProjectProvider>(context, listen: false)
.items
.isEmpty) {
myfuture = Provider.of<OpenProjectProvider>(context, listen: false)
.readinboxNotificationInd(checkId, currentPage);
}
}
super.initState();
//According to me the below line is creating the issue
_sc.addListener(() {
//
print('current page getmoredata: ${currentPage}');
if (_sc.position.pixels == _sc.position.maxScrollExtent) { //this statement is running multiple times
_getMoreData(currentPage++);
}
});
}
Output from Print statement
2 current page getmoredata: 1
67 current page getmoredata: 2