How to get from index in PageView onPageChanged in Flutter?
You can use PageView.builder, it will give you page index.
PageView.builder(
itemBuilder: (context, index) {
// index gives you current page position.
return _buildPage();
},
itemCount: listItemCount, // Can be null
)
Decrement page by 1 and store in a class Variable (call setState & modify) or local variable. If current-page is 0 set previousPage
to totalPageCount - 1.
_onPageViewChange(int page) {
print("Current Page: " + page.toString());
int previousPage = page;
if(page != 0) previousPage--;
else previousPage = 2;
print("Previous page: $previousPage");
}