BottomNavigationBar Vs BottomAppBar
In this blog, we are going to see how to implement BottomNavigationBar in flutter using the widgets BottomNavigationBar and BottomAppBar to see the difference between them.
We have a property named bottomNavigationBar in the scaffold, which is fixed at the bottom of the app, where we can display other buttons with either icons or labels using the BottomNavigationBar / BottomAppBar widgets. This allows us to select one icon / label at a time and move to that corresponding page / UI quickly.
BottomNavigationBar
In this it will automatically handle the screen based on index, here we can use some properties like:
type: BottomNavigationBarType.fixed or BottomNavigationBarType.shifted.
currentIndex: To define the starting index when the app starts.
items: It contains a list of BottomNavigationBarItems where icon and label is mandatory.
BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: const Color(0xff1c1f26),
unselectedItemColor: Colors.white,
selectedItemColor: Colors.white 54,
currentIndex: viewModel.index,
onTap: (value) {
viewModel.index = value;
viewModel.updateUI();
},
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.chat), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.info), label: ""),
BottomNavigationBarItem(icon: Icon(Icons.person), label: ""),
],
),
int index = 0;
getBottomNavigationWidget(int pos) {
switch (pos) {
case 0:
return const HomeScreen();
case 1:
return const ChatScreen();
case 2:
return const AboutScreen();
case 3:
return const ProfileScreen();
default:
return const MyHomePage();
}
}BottomAppBar
In this we have to define screens individually for navigation, here we some useful properties like:
Get Marvel Apps’s stories in your inbox
Join Medium for free to get updates from this writer.
notchMargin: To give space between bottomBar and floatingActionButton.
shape: AutomaticNotchedShape and CircularNotchedRectangle for designing the space between floatingActionButton.
child: Unlike BottomNavigationBar that only uses bottomNavigationBarItems, it can use any type of widget.
BottomAppBar(
notchMargin: 10,
clipBehavior: Clip.antiAlias,
color: const Color(0xff1c1f26),
shape: const AutomaticNotchedShape(
RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40),
topRight: Radius.circular(40),
),
),
RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(45)),
),
),
child: Padding(
padding: const EdgeInsetsDirectional.symmetric(horizontal: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: () => HomePageViewModel(),
child: const Icon(
Icons.home,
color: Colors.white,
),
),
InkWell(
onTap: () => const ChatScreen(),
child: const Icon(
Icons.chat,
color: Colors.white,
),
),
const SizedBox(
width: 12,
),
InkWell(
onTap: () => const AboutScreen(),
child: const Icon(
Icons.info,
color: Colors.white,
),
),
InkWell(
onTap: () => const ProfileScreen(),
child: const Icon(
Icons.person,
color: Colors.white,
),
),
],
),
),
),Key Differences between BottomNavigationBar and BottomAppBar:
Conclusion
We have implemented a bottomNavigationBar in Flutter that has two widgets i.e bottomNavigationBar and bottom app bar. Utilizing features such as the ability to select an icon/label at a time and move that corresponding page / UI quickly. By doing this, the screen is handled based on the index.
Give this blog a clap if it helped you. 👏👏👏👏
❤❤ Thanks for reading!!! ❤❤





