BottomNavigationBar 无法应用背景图片 - Flutter

BottomNavigationBar not able to apply background image - Flutter

当超过 3 个 BottomNavigationBarItem 时,

BottomNavigationBar 不应用背景图像。它显示白色背景而不是应用图像。请检查代码,如果我在代码中遗漏了什么,请告诉我。

 bottomNavigationBar: Container(
            decoration: BoxDecoration(
              image: DecorationImage(image: AssetImage('assets/images/tabbar_background.png'), fit: BoxFit.fill),
            ),
            child: BottomNavigationBar(
              backgroundColor: Colors.transparent,
              elevation: 0,
              items: [
                BottomNavigationBarItem(icon: Image.asset("assets/images/eplay.png"), title: Text('title')),
                BottomNavigationBarItem(icon: Image.asset("assets/images/games.png"), title: Text('title')),
                  BottomNavigationBarItem(icon: Image.asset("assets/images/retail-location.png"), title: Text('title')),
                 BottomNavigationBarItem(icon: Image.asset("assets/images/scan.png"), title: Text('title')),
                /*  BottomNavigationBarItem(icon: Image.asset("assets/images/scan.png"), title: Text('title')),
*/
              ],
            ),

添加 type: BottomNavigationBarType.fixed 作为 BottomNavigationBar 的 属性。


我以您的代码为例添加了一个演示:

  bottomNavigationBar: Container(
            decoration: BoxDecoration(
              image: DecorationImage(image: AssetImage('assets/images/tabbar_background.png'), fit: BoxFit.fill),
            ),
            child: BottomNavigationBar(
              backgroundColor: Colors.transparent,
              type: BottomNavigationBarType.fixed, // new line
              elevation: 0,
              items: [
                BottomNavigationBarItem(icon: Image.asset("assets/images/eplay.png"), title: Text('title')),
                BottomNavigationBarItem(icon: Image.asset("assets/images/games.png"), title: Text('title')),
                  BottomNavigationBarItem(icon: Image.asset("assets/images/retail-location.png"), title: Text('title')),
                 BottomNavigationBarItem(icon: Image.asset("assets/images/scan.png"), title: Text('title')),
                /*  BottomNavigationBarItem(icon: Image.asset("assets/images/scan.png"), title: Text('title')),
*/
              ],
            ),