2

我想知道如何使用应用程序栏制作通用导航抽屉和底部导航栏,以便仅将内容居中更改屏幕。就像在 android 片段中一样,我们在主要活动中制作抽屉导航和底部导航,并且在所有片段中它们都可以访问。当我在 main 上调用底部时它工作正常但是当我从抽屉打开相同的类时它的隐藏底部导航..我只需要任何类都将被称为底部导航抽屉并且底部导航总是在那里而且我不必在每个班级。

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


                ),
          ),
          )
        ],
      ),
       ),
      );
      }
      }
4

0 回答 0