1

我希望当用户未登录时,除了“Mon Compte”和“Annonces”选项卡将被激活之外,这些选项卡将被禁用。有没有办法关闭 CupertinoTabView 中的特定选项卡?除非用户登录,否则无法单击它?或者如果用户未连接,我该如何更改索引欢迎任何帮助,谢谢!

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(),
            );
          });
        }
      },
    );

  }
}
4

0 回答 0