单击底部导航栏时关闭Flutter抽屉

问题描述 投票:0回答:1

我有底部导航栏和抽屉。我希望在用户单击任何按钮导航图标时自动关闭抽屉。我不太确定该怎么做。

当用户在抽屉内部单击以下按钮时,我可以立即关闭抽屉


    void _onSelectItem(int index) {
    setState(() => _currentSelected= index);
    Navigator.of(context).pop(); // close the drawer
  }

但是抽屉永远粘在那里,直到我向后滑动。我也希望在用户单击底部导航栏时立即关闭抽屉。

  void onTappedBar(int index){
    index == 3
    ? _drawerKey.currentState.openDrawer()
    : setState((){
      _currentSelected = index;

    });
  }

这是我的底部导航栏

        bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.blueGrey[900],

        type: BottomNavigationBarType.fixed,
        onTap: onTappedBar,
        currentIndex: _currentSelected,
        showUnselectedLabels: true,
        unselectedItemColor: Colors.white,
        selectedItemColor: Color.fromRGBO(10, 135, 255, 1),
        items: <BottomNavigationBarItem> [ 
          BottomNavigationBarItem(icon: new Icon(Icons.home), title: new Text('Home')),
          BottomNavigationBarItem(icon: new Icon(Icons.search), title: new Text('Explore')),
          BottomNavigationBarItem(icon: new Icon(Icons.device_hub), title: new Text('Channels')),
          BottomNavigationBarItem(icon: new Icon(Icons.dehaze), title: new Text('More')),

        ],

      ),

我目前正在学习Flutter,因此任何建议将不胜感激。谢谢

flutter navigation navigation-drawer flutter-layout slidingdrawer
1个回答
0
投票

onItemSelected: {}添加到您的底部导航栏支架中,然后在该方法中添加Navigator.of(context).pop();。希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.