How to get rid of tabs in a tabbed application on user logout?

299 Views Asked by At

I have built a tabbed application with two tabs. The second tab has "Logout" option. On click of log out, the user must be taken to the login page. I am getting the login page here, but the problem is that I am also getting the two tabs at the bottom. Kindly help as I am new to flutter app development.

Below is the way I have built the tabs,

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],
            ),
          ),

Below is the code called on logout,

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

On log out, I am getting the login page but the tabs are also visible. Even the Navigator.pop(context) is giving me the same result. How do I pop the tabs? Please let me know...

1

There are 1 best solutions below

1
Taqi Tahmid Tanzil On

Try like this,update the body as your requirement

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