【发布时间】:2021-12-28 11:32:06
【问题描述】:
一般情况下,我们在appBar中使用drawer(位置drawer/endDrawer)。我必须将抽屉功能设置为带有主页、设置的底部导航栏项目。这 3 个项目将适用于所有页面,并且必须显示这三 (3) 个项目的选定索引。我怎样才能做到这一点。
class BottomNavBar extends StatefulWidget {
@override
_BottomNavBarState createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State<BottomNavBar> {
int _selectedIndex = 1;
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
currentIndex: _selectedIndex,
onTap: onTabTapped,
//for more than three items
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
icon: Icon(processIcon),
label: 'My Task',
),
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(settingIcon),
label: 'Setting',
),
BottomNavigationBarItem(
icon: Icon(menuIcon),
label: 'Menu',
),
],
);
}
void onTabTapped(int index) {
setState(() {
_selectedIndex = index;
print('index ${index}');
});
}
}
在这里,抽屉将被导航到菜单中。
【问题讨论】:
-
你能详细描述一下这个问题吗?我不太明白
-
主要我需要通过单击底部导航栏项目上的菜单按钮来打开和关闭抽屉。下一部分是假设我想从我的应用程序的任何页面进入设置页面,当我单击并进入设置页面时,设置将显示为已选择
标签: android ios flutter dart flutter-layout