Click here to Skip to main content
15,569,644 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am working on flutter footer navigation, I have a file where I initiate all parameters needed, like so:

  const Db5BottomNavigationBarItem({
    required this.icon,
    this.title,
    Widget? activeIcon,
    this.backgroundColor,
    required this.onTap,
  }) : activeIcon = activeIcon as String? ?? icon;

  
  final String icon;
  final String activeIcon;
  final Widget? title;
  final Color? backgroundColor;
  final Function onTap;
}

This is how I'm using it on my footer component:
child: Db5BottomNavigationBar(
         items: <Db5BottomNavigationBarItem>[
           Db5BottomNavigationBarItem(
             icon: db5_ic_home,
             onTap: () {},
           ),
           Db5BottomNavigationBarItem(
             icon: db5_ic_heart,
             onTap: () {
               Navigator.push(context,
                   MaterialPageRoute(builder: (context) => new Health()));
             },
           ),
           Db5BottomNavigationBarItem(
             icon: db5_ic_msg,
             onTap: () {},
           ),
           Db5BottomNavigationBarItem(
             icon: db5_ic_setting,
             onTap: () {},
           ),
         ],
         // currentIndex: _selectedIndex,
         unselectedIconTheme: IconThemeData(color: db5_icon_color, size: 24),
         selectedIconTheme: IconThemeData(color: db5_colorPrimary, size: 24),
         onTap: (int index) {
           setState(() {
             // _selectedIndex = index;
           });
         },
         type: Db5BottomNavigationBarType.fixed,
       ),

The problem is, once the button is clicked, let say the first:
onTap: () {
                Navigator.push(context,
                    MaterialPageRoute(builder: (context) => new Health()));
              },

No error at all, and, no response.
What am I doing wrong?

What I have tried:

onTap: () {
                Navigator.push(context,
                    MaterialPageRoute(builder: (context) => new Health()));
              },
Posted
Updated 16-Aug-21 1:05am
v2
Comments
Afzaal Ahmad Zeeshan 14-Aug-21 16:19pm    
1. I would set a debugger and see if the line inside the onTap method gets called or not.
2. Verify if the tap is on the right widget. Sometimes your widget is hidden under another widget, thus not receiving any tap notifications from the framework.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900