📱
Flutter の BottomNavigationBar で4つのアイテムを設定するとテキストが表示されない問題の解決方法
なにこれ
Flutter で BottomNavigationBar を使ってメニューを作成しようと思ったらテキストが表示されなくて困ったので、その時の解消方法をメモ
事象
3つまでだとこのように良い感じに表示されるが
4つ以上になるとテキストが見えなくなった!
解決方法
type: BottomNavigationBarType.fixed
で固定にしないといけないらしい。
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed, // このプロパティを追加する
items: // ...,
)
原因
4つ以上にすると BottomNavigationBarType.shifting
に自動的に切り替わってしまい、テキストが表示されないようになってしまうとのこと。
公式ページ:https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html
The bottom navigation bar's type changes how its items are displayed. If not specified, then it's automatically set to BottomNavigationBarType.fixed when there are less than four items, and BottomNavigationBarType.shifting otherwise.
そして…
無事に直った!よかったよかった
Discussion