I am wanting to include a Bottom Navigation Bar in my application that will be displayed on some pages but not other. As I understand the the Flutter BottomNavigationBar widget re-renders the Scaffold Body property and does not actually route to another page and always shows the navigation bar. Would anyone have some advice on how I can have a bottom navigation that would look like the following where Tab 1 and Tab 3 route to a screen showing the navigation bar and Tab 2 and Tab 3 are screens that don't show the navigation bar?
CodePudding user response:
I believe you want to show the bottomNavBar in tab 1and 3 while hiding it in 2 and 4 right? I presume you have a variable that keeps track of the selected index lets call it int _selectedIndex = 0. In the bottomNavigation property you can show and not show it like below
bottomNavigationBar: _selectedIndex.isEven ? null: BottomNavigationBar()
Here it checks the _selectedIndex value (0,1,2,3 in this case) and if that is odd you show the page and the navigations (Tab 1 & 3) while if it is even (Tab 2 & 4) then you supply a null thus not showing the navigation. The only concern becomes how to navigate outside the two tabs without navigation but this should solve your immediate problem

