どうも、ちょげ(@chogetarou)です。
BottomNavigationBarItemのラベルを選択していない時は、非表示になるようにする方法を紹介します。
方法

BottomNavigationbarItemのラベルを選択していない時は非表示になるようにするには、BottomNavigationBarの引数「showUnselectedLabels」を使います。
具体的には、BottomNavigationBarの引数「showUnselectedLabels」にfalseを指定します。
BottomNavigationBar(
showUnselectedLabels: false,
items: [
・・・
],
currentIndex: _currentIndex,
onTap: _onTap,
),
これでBottomNavigationBarItemのラベルを選択していない時は非表示にすることが出来ます。
使用例
以下は、使用例です。
@override
Widget build(BuildContext context) {
return Scaffold(
body: _pages[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
showUnselectedLabels: false,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
),
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.favorite),
label: 'Favorite',
),
],
currentIndex: _currentIndex,
onTap: _onTap,
),
);
}
まとめ
BOttomNavigationbarItemのラベルを非選択中は非表示にするには、BottomNavigationBarの引数「showUnselectedLabels」を使います。
コメント