flutter app练习系列1 bottomnavigationbar 底部导航栏切换
pagerview 配合bottomnavigationbar 实现页面切换导航
1.主体代码
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: PageView.builder(
onPageChanged: (index){
setState(() {
_selectedIndex=index;
});
},
controller: _pagerControler,
itemCount: listPager.length,
// ignore: missing_return
itemBuilder: (BuildContext context,int index){
if(index==0){
return listPager[0];
}else if(index==1){
return listPager[1];
}else if(index==2){
return listPager[2];
}else if(index==3){
return listPager[3];
}else if(index==4){
return listPager[4];
}
}
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
type: BottomNavigationBarType.fixed,
onTap: (index){
// 切换时没有动画效果
// _pageController.jumpToPage(index);
// 切换时添加动画效果
// _pagerControler.animateToPage(index,
// duration: new Duration(seconds