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

アイコン無しのBottomNavigationBarを表示するには、SizedBox.shrink()を使います。
具体的には、BottomNavigationBarItemの引数「icon」にSizedBox.shrink()を指定します。
BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: SizedBox.shrink(),
label: 'ラベル',
),
BottomNavigationBarItem(
icon: SizedBox.shrink(),
label: 'ラベル',
),
BottomNavigationBarItem(
icon: SizedBox.shrink(),
label: 'ラベル',
),
・・・
],
currentIndex: _currentIndex,
onTap: _onTap,
),
これでアイコン無しのBottomNavigationBarを表示することが出来ます。
使用例
以下は、使用例です。
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
var _currentIndex = 1;
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: [
Container(
child: Text('Settings'),
alignment: Alignment.center,
color: Colors.green[100],
),
Container(
child: Text('Home'),
alignment: Alignment.center,
color: Colors.blue[100],
),
Container(
child: Text('Favorite'),
alignment: Alignment.center,
color: Colors.pink[100],
),
],
),
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,
),
);
}
void _onTap(int index) {
setState(() {
_currentIndex = index;
});
}
}
まとめ
アイコン無しのBottomNavigationBarを表示するには、SizedBox.shrink()を使います。
コメント