Is there a way to show the BottomNavigationBar on every page? Currently the BottomNavigationBar disappears when pushing the button but I want the BottomNavigationBar to always be displayed even when routing to a new page. The following code shows my BottomNavigationBar and my detail page.
class BottomNavBar extends StatefulWidget {
const BottomNavBar({Key? key}) : super(key: key);
@override
State<BottomNavBar> createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State<BottomNavBar> {
int currentIndex = 0;
final screens = const [Home(), Search()];
@override
Widget build(BuildContext context) {
return Scaffold(
body: screens[currentIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: bottomNav,
unselectedItemColor: Colors.grey,
selectedFontSize: 12,
unselectedFontSize: 12,
currentIndex: currentIndex,
onTap: (index) => setState(() => currentIndex = index),
items: const [
BottomNavigationBarItem(
icon: Icon(
Icons.home_filled,
size: 28,
),
label: 'Home'),
BottomNavigationBarItem(
icon: Icon(
Icons.search_rounded,
size: 28,
),
label: 'Search'),
]));
}
}
My detail page:
class Home extends StatelessWidget {
const Home({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: IconButton(
icon: const Icon(Icons.abc),
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => const Page1()));
},
)),
);
}
}
class Page1 extends StatelessWidget {
const Page1({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.red,
);
}
}