Flutter Bottom Navigation Bar with PageView
You just need to use onPageChanged
property of the PageView to catch the current page number.
PageView(
controller: _pageController,
children: <Widget>[
ProfilePage(),
HomeTables(),
ShoppingPage(),
],
onPageChanged: (page) {
setState(() {
_selectedIndex = page;
});
},
);
Just add onPageChanged property of PageView
and assign the pageIndex
to _selectedIndex
property, then reload the widget using setState()
method.
onPageChanged - Called whenever the page in the center of the viewport changes.
PageView(
....
onPageChanged: (pageIndex) {
setState(() {
_selectedIndex = pageIndex;
});
},
...
)