[Flutter]BottomNavigationBarの影の大きさを設定するには?

Flutter

どうも、ちょげ(@chogetarou)です。

BottomNavigationBarの影の大きさを設定する方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

BottomNavigationBarの影の大きさを設定するには、引数「elevation」を使います。

具体的な方法としては、引数「elevation」に影の大きさを指定します。

BottomNavigationBar(
  elevation: /*影の大きさ*/,
  items: [
      //BottomNavigationBarItem
  ],
  currentIndex: _currentIndex,
  onTap: _onTap,
),

これで影の大きさを設定できます。

影の大きさを設定できると言っても、ほんの少し大きくなるだけです。

もし大きい影を設定したいならば、Containerを使います。

Container(
  decoration: BoxDecoration(boxShadow: [
    BoxShadow(
      color: Colors.grey,
      blurRadius: 8,
      spreadRadius: 8,
    ),
  ]),
  child: BottomNavigationBar(
    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,
  ),
),

使用例

以下は、使用例です。

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        elevation: 50,
        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,
      ),
    );
  }

まとめ

BottomNavigationbarの影の大きさを設定するには、引数「elevation」を使います。

コメント

タイトルとURLをコピーしました