【发布时间】:2020-07-28 20:22:02
【问题描述】:
我有底部导航栏和抽屉。我希望抽屉在用户单击任何按钮导航图标时自动关闭。我不确定该怎么做。
当用户点击抽屉内部时,我可以立即关闭抽屉,如下所示
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