I've created a BottomNav that has 4 buttons and it navigates fine between them. But i want this BottomNav to be visible in all screens of the app (those screens that are not directly attached to the BottomNav).
for example: my bottomNav has 4 screens (home, profile, notices, and more), the bottomNav appears perfectly in them, but i want it to appear also in another 2 screens (permissions, vacations) which are accessed from button in Home screen
How can I approach such a thing?
here's my BottomNav code to be clear:
int _selectedIndex = 0;
//list of widgets that already exist on the bottomNav
static List<Widget> _screens = <Widget>[
PermissionsRequestScreen(),
HomeScreen(title: 'Home'),
NoticesScreen(),
ProfileScreen(),
MoreScreen(),
];
////////////////////////
// bottom nav bar navigator function
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
/////////////////////
@override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(),
body: Center(
child: _screens.elementAt(_selectedIndex),
),
//bottomNavBar
bottomNavigationBar: createBottomNavBar(),
);
}
///////////////////
// bottom navigation Bar
Widget createBottomNavBar() {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [primaryColor, secondaryColor],
stops: [8, 8],
),
),
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _selectedIndex,
onTap: _onItemTapped,
backgroundColor: Colors.transparent,
iconSize: 22,
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white24,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.info),
label: 'Notices',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
BottomNavigationBarItem(
icon: Icon(Icons.more_horiz),
label: 'More',
),
],
enableFeedback: true,
),
);
}
I've tried to use pushReplacement when moving from the bottomNav screen to the next one but it doesn't work.
So, i.e.: How to keep the BottomNav visible in the screens that aren't directly attached to the BottomNav??