bottomNavigationBar widget的用法进行介绍,bottomNavigationBar主要用于在App页面底部显示导航栏。
具体用法参照代码,BottomNavigationBarItem都会被放到items数组里。
当用户点击导航栏按钮时,setState会将index传给selectedIndex, 被选中的Icon会高亮。
int selectdIndex = 0;
void _onItemTapped(int index){
setState(){
selectdIndex = index;
}
}
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.add),
label: '追加'
),
BottomNavigationBarItem(
icon: Icon(Icons.close),
label: '削除'
)
],
currentIndex: selectdIndex,
onTap: _onItemTapped,
),