How can i disable a particular tab in CupertinoTabView, to be able to click?

255 views Asked by At

I want when the user is not logged in the tabs will be disabled except the tab of "Mon Compte" and "Annonces" will be activated. Is there a way to turn off a particular tab in the CupertinoTabView? so that it cannot be clicked unless the user is logged in? or how can I change index if the user is not connected Any help is welcome, thank you!

class BottomMenu extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _BottomMenuState();
  }
}

class _BottomMenuState extends State<BottomMenu> {
   static int currentTab = 3; // to keep track of active tab index


 @override
  Widget build(BuildContext context) {


    SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarBrightness: Brightness.light,
        systemNavigationBarColor: Colors.transparent,
        systemNavigationBarIconBrightness: Brightness.light,
      ),
    );

    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        currentIndex:  currentTab ,
        activeColor: Theme.of(context).primaryColor,
        backgroundColor: Theme.of(context).backgroundColor,
        inactiveColor: Theme.of(context).disabledColor,
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.search),
            title: Text(
                "Matching"
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.dashboard),
            title:
            Text(
                "Annonces"
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(MenuIcon.favorite__1_),
            title:
            Text("Favoris"),
          ),
          BottomNavigationBarItem(
            icon: Icon(MenuIcon.user__1_),
            title: Text(
                "Mon Compte"
            ),
          ),
        ],
      ),
      tabBuilder: (context, index) {
        switch (index) {

          case 0:
            return CupertinoTabView(builder: (context) {


                return CupertinoPageScaffold(
                  child: Matching(),
                );

            }

            );
          case 1:
            return CupertinoTabView(builder: (context) {

              return CupertinoPageScaffold(
                child: Offers(),
              );
            });
          case 2:
            return CupertinoTabView(builder: (context) {

              return CupertinoPageScaffold(
                child: Favorites(),
              );
            });
          default: return CupertinoTabView(

              builder: (context) {

            return CupertinoPageScaffold(
              child: Login(),
            );
          });
        }
      },
    );

  }
}
0

There are 0 answers