class BottomPage extends StatefulWidget{
@override
State<StatefulWidget> createState() =>_BottomPage();
}
class _BottomPage extends State<BottomPage>{
var pageList=[HomePage(),NullPage(),NullPage(),PersonPage()];//要显示的内容
int currentIndex=3;
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(bottomNavigationBar: BottomNavigationBar(items: [
//bottomNavigationBar的图标
BottomNavigationBarItem(icon: Icon(Icons.home),label: "房屋"),
BottomNavigationBarItem(icon: Icon(Icons.movie),label: "场景"),
BottomNavigationBarItem(icon: Icon(Icons.message),label: "消息"),
BottomNavigationBarItem(icon: Icon(Icons.person),label: "我的")
],
type: BottomNavigationBarType.fixed,//bottomNavigationBar的显示模式
currentIndex: currentIndex,//初始按钮选择位置
onTap: (index){index是点击对应按钮返回的索引值
currentIndex=index;//自定义的currentIndex获取index的值
setState(() {
});
},
),
body: IndexedStack(index: currentIndex,//初始显示的内容位置
children: pageList,),//添加内容的集合
);
}
}