[Flutter]BottomNavigationBarの背景を透明にするには?

Flutter

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

BottomNavigationBarの背景を透明にする方法を紹介します。

スポンサーリンク

方法

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

まず、BottomNavigationBarの引数「color」に「Colors.transparent」、引数「elevation」に「0」を指定します。

BottomNavigationBar(
  backgroundColor: Colors.transparent,
  elevation: 0,
  items: [
    ・・・
  ],
  currentIndex: _currentIndex,
  onTap: _onTap,
),

そして、Scaffoldの引数「extendBody」に「true」を指定します。

Scaffold(
  extendBody: true,
  bottomNavigationBar: BottomNavigationBar(
    backgroundColor: Colors.transparent,
    elevation: 0,
    items: [
      ・・・
    ],
    currentIndex: _currentIndex,
    onTap: _onTap,
  ),
);

これでBottomNavigationBarの背景が透明になります。

使用例

以下は、使用例です。

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBody: true,
      body: IndexedStack(
        index: _currentIndex,
        children: _pages,
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        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の背景を透明にするには、BottomNavagationBarの引数とScaffoldの引数「extendBody」を使います。

コメント

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