Reputation: 5532
I used PageView to write a list in the vertical direction. Now when I slide the list up or down (my finger doesn't leave the screen), onPageChanged will execute. Is there a way to detect that the onPageChanged method will only be executed when the finger leaves the screen.Part of the code below:
SizedBox(
width: 200,
height: 200,
child: PageView(
controller: pageController,
scrollDirection: Axis.vertical,
onPageChanged: (index) {
setState(() {
pageIndex = index;
});
},
children: _buildCardList()),
)
like below:
Upvotes: 1
Views: 1049
Reputation: 4933
Wrap your page view with a Notification listener like below:
SizedBox(
width: 100,
height: 100,
child: NotificationListener<ScrollNotification>(
onNotification: (notification)
{
if(notification is ScrollEndNotification)
{
var pageIndex = pageController.page;
}
},
child: PageView(
controller: pageController,
scrollDirection: Axis.vertical,
onPageChanged: (index) {
},
children: _buildCardList()),
),
)
Upvotes: 3
Reputation: 1580
you can do it like that;
int currentPage;
.
.
.
onPageChanged(int page){
if(currentPage != page){
setState((){
currentPage = page;
});
}
}
Upvotes: -1