【发布时间】:2020-09-08 13:47:46
【问题描述】:
我是新来的 Flutter,一直在尝试使用 BottomNavigationBar。问题是,我根据需要制作了条形图,但是当 Switch 设置为 true 但无法找到解决方法时,我需要它来更新其项目。
我有两个List<BottomNavigationBarItems>,它们有两个不同的导航栏项目,我将它们分配给第三个列表,其中包含取决于开关状态的活动项目。这个变量是在我的 navbarItem 中设置项目的变量,但 setState() 似乎不会重新构建 navBar。
有没有办法更新项目或者我必须用其他小部件制作自己的导航栏?
List<BottomNavigationBarItem> nonReadyBottomItems = [
//some items
];
List<BottomNavigationBarItem> readyBottomItems = [
some other items
];
List<BottomNavigationBarItem> = nonReadyBottomItems;
Scaffold(
body: Center(
child: Switch(
value: switchConnect,
onChanged: (bool boolean) {
setState(() {
switchConnect = boolean;
});
}),
),
bottomNavigationBar: BottomNavigationBar(
onTap: (int i) {
setState(() {
pageIndex = i;
if (switchConnect) {
activeItems = readyBottomItems;
} else if (!switchConnect) {
activeItems = nonReadyBottomItems;
}
});
},
currentIndex: pageIndex,
type: BottomNavigationBarType.fixed,
items: activeItems,
),
);
【问题讨论】:
标签: flutter navigationbar