I have a bottom navigation bar with some tabs and I want to animate the icons of them when I switch page, without an external package.
And I have one more question, I added a view pager to switch pages swiping, and taping in the nav bar icons, but I got an error. For example: I am in the page 1, and I want to switch to page 3, while it is going and passes page 2, it goes back and stay in page 2.
_onPageChanged method:
_onPageChanged(int index) {
setState(() {
_pageController.animateToPage(index,
duration: const Duration(milliseconds: 200), curve: Curves.easeInOut);
_activePage = index;
});
}
BottomNavBar(from scratch) and ViewPager:
bottomNavigationBar: BottomNavBar(
activeTab: _activePage,
onTabTap: _onPageChanged,
tabs: const [
BottomNavBarItem(
icon: Icon(Icons.icon_1, color: gray),
selectedIcon: Icon(Icons.icon_1_selected, color: white)
),
BottomNavBarItem(
icon: Icon(Icons.icon_2, color: gray),
selectedIcon: Icon(Icons.icon_2_selected, color: white)
),
BottomNavBarItem(
icon: Icon(Icons.icon_3, color: gray),
selectedIcon: Icon(Icons.icon_3_selected, color: white)
),
],
),
body: PageView(
controller: _pageController,
onPageChanged: _onPageChanged,
children: _pages,
),