0

I have a convex bottom bar and the last tab is a Menu that opens a drawer when clicked. But I'm having troubles when the drawer is closed. As the tab Menu only opens a drawer I wish it could return to previous tab when drawer closes, but the Menu tab keeps active. The tab only changes when it is clicked. So how can I call the onTab property of convex_tab_bar when the drawer is closed?

...
    return Scaffold(
  key: _scaffoldKey,
  drawer: Drawer(
    child: ListView(
      padding: EdgeInsets.zero,
      children: [
        const DrawerHeader(
          decoration: BoxDecoration(
            color: Colors.blue,
          ),
          child: Text('Drawer Header'),
        ),
        ListTile(
          title: const Text('Item 1'),
          onTap: () {},
        ),
      ],
    ),
  ),
  onDrawerChanged: (isOpen) {
    if (!isOpen) {
      setState(() {
        _currentOption = _previousOption;
      });
      changeTab(context, _previousOption);
    }
  },
  body: Container(
    child: _currentPage,
  ),
  bottomNavigationBar: StyleProvider(
    style: Style(),
    child: ConvexAppBar(
      style: TabStyle.fixedCircle,
      backgroundColor: Colors.white,
      color: Colors.grey,
      activeColor: _currentOption == 1
          ? const Color(0xffa98e47)
          : const Color(0xff00c9ff),
      items: [
        TabItem(
          icon: const Icon(
            ReceivedIcon.receivedIcon,
            color: Colors.grey,
            size: 12,
          ),
          title: AppLocalizations.of(context)!.received,
          activeIcon: const Icon(
            ReceivedIcon.receivedIcon,
            color: Color(0xff00c9ff),
            size: 12,
          ),
        ),
        TabItem(
          icon: const Icon(SentIcon.sentIcon, color: Colors.grey),
          title: AppLocalizations.of(context)!.sent,
          activeIcon: const Icon(SentIcon.sentIcon, color: Color(0xffa98e47)),
        ),
        const TabItem(
          icon: Icon(
            Icons.add_rounded,
            size: 48,
            color: Colors.white,
          )
        ),
        TabItem(
          icon: Icons.notifications,
          title: AppLocalizations.of(context)!.notifications
        ),
        TabItem(
          icon: Icons.menu, 
          title: AppLocalizations.of(context)!.menu
        ),
      ],
      onTap: (int i) {
        changeTab(context, i);
      },
  ),
  ),
);
Gustavo F.
  • 95
  • 13

2 Answers2

0

create a function onTapHandler in your class ... put the referece on your ConvexAppBar(onTap:onTapHandler ...) and now you are able to call the onTapHandler in your onDrawerChanged handler

Maurice Raguse
  • 4,437
  • 2
  • 29
  • 46
  • It didn't work, the same result remains. I did the following: void onTapHandler(int index) { changeTab(context, index); } -In ConvexAppBar: ...onTap: onTapHandler, -In onDrawerChanged: onDrawerChanged: (isOpen) { if (!isOpen) { setState(() { _currentOption = _previousOption; }); onTapHandler(_previousOption); } }, – Gustavo F. Jan 04 '22 at 16:21
0

try this https://github.com/hacktons/convex_bottom_bar/blob/master/doc/issue-change-active-tab-index.md (Change active tab index programmaticlly)

Maurice Raguse
  • 4,437
  • 2
  • 29
  • 46