どうも、ちょげ(@chogetarou)です。
BottomNavigationBarのアイコンを削除する方法を紹介します。
方法

BottomNavigationbarのアイコンを削除するには、 SizedBoxを使います。
具体的な方法としては、BottomNavigationBarの引数「icon」にSizedBox.shrink()を指定します。
BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: SizedBox.shrink(),
label: 'ラベル',
),
],
currentIndex: _currentIndex,
onTap: _onTap,
),
これでBottomNavigationBarのアイコンを削除することが出来ます。
使用例
以下は、使用例です。
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: [
Container(
child: Text('Settings'),
alignment: Alignment.center,
),
Container(
child: Text('Home'),
alignment: Alignment.center,
color: Colors.yellow,
),
Container(
child: Text('Favorite'),
alignment: Alignment.center,
color: Colors.pink.withOpacity(0.3),
),
],
),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: SizedBox.shrink(),
label: 'Settings',
),
BottomNavigationBarItem(
icon: SizedBox.shrink(),
label: 'Home',
),
BottomNavigationBarItem(
icon: SizedBox.shrink(),
label: 'Favorite',
),
],
currentIndex: _currentIndex,
onTap: _onTap,
),
);
}

まとめ
BottomNavigationBarのアイコンを削除するには、SizedBox.shrink()を使います。
コメント