EDIT: Solution below
Goal/Problem: I'm styling a BottomNavigationBar with a FAB. I'd like to move items 2 and 3 a bit further apart, so they don't hug the FAB so closely. Screenshots and code below.
Failed solutions:
Screenshots:
No padding:
With horizontal Padding for demonstration purposes, icons and labels not in sync:
Code (with relevant Padding on zero):
BottomNavigationBarItem bottomNavIcon({
required BuildContext context,
required Image icon,
required Image icon_active,
required String label,
}) {
return BottomNavigationBarItem(
icon: Padding(
padding: EdgeInsets.only(
top: 6.h,
bottom: 3.h,
left: 0.w
right: 0.w,
),
child: icon,
),
activeIcon: Padding(
padding: EdgeInsets.only(
top: 6.h,
bottom: 3.h,
left: 0.w
right: 0.w,
),
child: icon_active,
),
label: label,
);
}
Desperate solution: I'm considering placing an invisible icon in the middle and have the onTap method of the navbar do nothing for index 2 ... but that really feels like a hack.
EDIT//The "solution":
I ended up using the hack.Thanks to MSARkrish for giving me this snippet:
BottomNavigationBarItem(
backgroundColor: Theme.of(context).backgroundColor,
icon: const SizedBox.shrink(),
label: "",
),
Things I needed to do to make it work:
I added a SizedBox in the list holding the pages; otherwise the icons ake the ontap do nothing for index 2:
onTap: (index) => index != 2 ? selectPage(index) : () {},
I also disabled feedback for the the buttons, otherwise you'd hear a pop, when tapping the invisible button.
I already had higjhlight colors and splash colors of. I guess they'd cause issues as well, if they were enabled.
God...I hate the BottomNavigationBar widget ... never gonna use that one again... Better to create it from scratch.
I also faced similar situation in one of our office project. We did this hack to achieve UI like yours.
BottomNavigationBarItem(
backgroundColor: Theme.of(context).backgroundColor,
icon: const SizedBox.shrink(),
label: "",
),