属性说明:
- currentIndex:表示当前显示页面的索引值
onTap():表单点击导航栏的时候触发的函数
onTap(int index){ // index表示的是当前页面的索引值print("当前显示的是第${index+1}个页面");}
items[]: 表示的是导航栏中的显示的元素列表,
@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text("Flutter"),),body: viewList[_currentIndex],bottomNavigationBar: BottomNavigationBar(currentIndex: _currentIndex,onTap: (int index){setState(() {_currentIndex = index;});},items: const [BottomNavigationBarItem(icon: Icon(Icons.home),label: "主页",),BottomNavigationBarItem(icon: Icon(Icons.category),label: "分类",),BottomNavigationBarItem(icon: Icon(Icons.settings),label: "设置")],),);}
