【问题标题】:How to get rid of tabs in a tabbed application on user logout?如何在用户注销时摆脱选项卡式应用程序中的选项卡?
【发布时间】:2021-04-16 10:25:09
【问题描述】:

我已经构建了一个带有两个选项卡的选项卡式应用程序。第二个选项卡具有“注销”选项。单击注销后,必须将用户带到登录页面。我在这里获得了登录页面,但问题是我还在底部获得了两个选项卡。请提供帮助,因为我是 Flutter 应用程序开发的新手。

以下是我构建标签的方式,

List<Widget> _children = [
    Test1(), //this is the first tab 
    Test2(), //this is the second tab that has logout option
  ];

    home: DefaultTabController(
            length: 2,
            child: Scaffold(
              bottomNavigationBar: BottomNavigationBar(
                onTap: onTabTapped, 
                currentIndex: _currentIndex, 
                items: [
                  BottomNavigationBarItem(
                    icon: new Icon(CustomIcons.home),
                    title: new Text(''),
                  ),
                  BottomNavigationBarItem(
                    icon: new Icon(CustomIcons.profile),
                    title: new Text(''),
                  ),
                ],
              ),
              body: _children[_currentIndex],
            ),
          ),

以下是注销时调用的代码,

Navigator.of(context).pushNamedAndRemoveUntil('/login', (Route<dynamic> route) => false);

注销时,我得到了登录页面,但选项卡也可见。甚至 Navigator.pop(context) 也给了我相同的结果。如何弹出标签?请告诉我...

【问题讨论】:

  • 取决于您的其余代码,但如果您 pop 带有标签的页面,如果我理解正确的话,这应该会让您回到必须标签的初始登录屏幕。所有连续的页面都堆叠在一起。 pop 删除最上面的一个,留下下面的一个
  • 否,登录屏幕没有标签。它只有两个文本字段(用户名和密码)。成功登录后,用户将被带到主屏幕(这有两个选项卡)。在其中一个选项卡中有注销选项。单击注销用户将进入登录屏幕,但这里的问题是底部的选项卡也出现在我不想要的登录屏幕中。
  • 这是我的意思。我会尝试用标签弹出页面。 - 刚刚看到我有一个类型“返回到必须选项卡的初始登录屏幕”,应该是“返回没有选项卡的初始登录屏幕,”
  • 我已经用代码更新了我的问题。请帮忙

标签: flutter dart uitabbar tabbar tabbed


【解决方案1】:

像这样尝试,根据您的要求更新正文

return MaterialApp(
    home: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            iconTheme: IconThemeData(color: kTextColor,size: 10),
            title: Text('Client Information',style: TextStyle(fontFamily: 'Poppins-regular',color: kTextColor),),
            backgroundColor: kPrimaryLightColor,
            bottom: TabBar(
              labelColor: kTextColor,
                tabs: [
                  Tab(text: 'Job Details',),
                  Tab(text: 'Client Information',)
                ]),
          ),
          drawer: FreelancerAppDrawer(),
          body: TabBarView(children: [
            JobDetails(),
            ClientInfo()
          ]),
        ))
);

【讨论】:

  • 我使用了这个代码。但是遇到同样的问题.. 注销时标签并没有消失。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-14
  • 1970-01-01
相关资源
最近更新 更多