2

I want to know how can i make generic Navigation drawer and bottom navigation bar with app bar so just center content only change of screen. like in android fragment we make navigation drawer and bottom navigation in main activity and in all fragments they are accessible. when i call bottom on main its working fine but when i open same class from drawer its hide bottom navigation .. i just need any class will be called bottom navigation drawer and bottom navigation always be there and i don't have to set in every class.

class TabBarController extends StatefulWidget {
 @override
_TabBarControllerState createState() => _TabBarControllerState();
}

class _TabBarControllerState extends State<TabBarController> {
int _currentIndex = 0;

final List<Widget> _screens = [
HomeScreen(),
Helpers.hasPrivilege(Privileges.MONITORING)? MonitoringScreen() :  ShopsListScreen(),
NotificationsListScreen(),
ProfileScreen()
];

final List<Widget> _titleIcons = [
Text('HOME'),
Text('MENU'),
Text('NOTIFICATIONS'),
Text('PROFILE'),
];

@override
void initState() {
// TODO: implement initState
super.initState();

}

@override
Widget build(BuildContext context) {

return _screenView();
}



Widget _screenView() {
return Scaffold(

  body: IndexedStack(
    index: _currentIndex,
    children: _screens,
  ),
  bottomNavigationBar: BottomNavigationBar(
      showSelectedLabels: true,
      showUnselectedLabels: true,
      type: BottomNavigationBarType.fixed,
      selectedItemColor: appColor,
      unselectedItemColor: Colors.grey.withOpacity(0.5),
      currentIndex: _currentIndex,
      onTap: (index) {
        setState(() {
          _currentIndex = index;
          setState(() {});
        });
      },
      items: [

        BottomNavigationBarItem(
            icon: Icon(Icons.home), title: Text('Home')),
       BottomNavigationBarItem(icon: Icon(Icons.shop), title: Text('MENU')) ,
        BottomNavigationBarItem(
            icon: Icon(Icons.notifications), title: Text('Notifications')),
        BottomNavigationBarItem(
            icon: Icon(Icons.person), title: Text('Profile')),
      ]
  ),
  drawer: AppDrawer(),
);
}}


 class AppDrawer extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return Drawer(
  child: Container(
    color: Colors.red[900],
    child: Column(
      children: <Widget>[
        SizedBox(width: double.infinity,height: 200.0),
        ListTile(

          leading: Icon(FontAwesomeIcons.home,color: Colors.white),
          title: Text(AppStrings.home,style: TextStyle(color: Colors.white)),
            onTap: ()
            {
              Navigator.pop(context);
              Navigator.push(context,MaterialPageRoute(builder: (context) => 
 TabBarController()));

            }


        ),
        ListTile(

          leading: Icon(FontAwesomeIcons.user,color: Colors.white),
          title: Text(AppStrings.profile,style: TextStyle(color: Colors.white)),
            onTap: ()
            {
              Navigator.pop(context);
              Navigator.push(context,MaterialPageRoute(builder: (context) => 
 ProfileScreen()));
            }


        ),
        ListTile(

          leading: Icon(FontAwesomeIcons.store,color: Colors.white),
          title: Text(AppStrings.shops,style: TextStyle(color: Colors.white)),
            onTap: ()
            {
              Navigator.pop(context);
              Navigator.push(context,MaterialPageRoute(builder: (context) => 
 ShopsListScreen()));
            }


        ),
        ListTile(

          leading: Icon(FontAwesomeIcons.receipt,color: Colors.white),
          title: Text(AppStrings.orders,style: TextStyle(color: Colors.white)),
            onTap: ()
            {
              Utils.showToastShort(context, AppStrings.orders);
            }


        ),
        Divider(),
        Expanded(
          child: Align(
            alignment: FractionalOffset.bottomCenter,
            child:
            ListTile(

                leading: Icon(FontAwesomeIcons.powerOff,color: Colors.white),
                title: Text(AppStrings.logout,style: TextStyle(color: Colors.white)),
                onTap: ()
                {
                  Navigator.pop(context);

                  UserPreferencesManager.clearAll();
                   Navigator.push(context,MaterialPageRoute(builder: (context) => 
           LoginScreen()));
                }


                ),
          ),
          )
        ],
      ),
       ),
      );
      }
      }
Ali Sidhu
  • 119
  • 9

0 Answers0