Flutter-如何隐藏/删除BottomNavigationBarItem的标题

Kin*_*ics 4 dart flutter

所以我有这个扑扑的应用程序,并且我试图隐藏或删除标题。我试图将标题保留为空字符串,即,new Text("")但与导航栏的对齐方式混淆了。

期望的结果:

她是我要达到的目标

我得到什么(如果我将标题保留为空字符串):

在此处输入图片说明

Ika*_*ský 22

现在,您只需为选定或未选定的项目禁用标签:

bottomNavigationBar: BottomNavigationBar(
  showSelectedLabels: false,   // <-- HERE
  showUnselectedLabels: false, // <-- AND HERE
  items: [
    BottomNavigationBarItem(
      icon: Icon(Icons.person),
      title: Text('Personal')
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.notifications),
      title: Text('Notifications'),
    ),
  ]
  ...
)
Run Code Online (Sandbox Code Playgroud)

...导致:

结果

  • `title` 现已弃用,这与标签完美配合! (2认同)

Dan*_*lev 18

由于此功能尚未实现,因此有两种解决方法。

  1. 通过Container(height: 0.0)而不是Text("")
  2. 创建小部件并使用它而不是Flutter的底部导航。来源

更新:

只需将其添加到您的BottomNavigationBar

showSelectedLabels: false,
showUnselectedLabels: false,
Run Code Online (Sandbox Code Playgroud)


Soo*_*rya 10

在新版本的flutter中,title被贬值了,我们必须提供label。因此,将标签设置为空字符串

          BottomNavigationBarItem(
            label: '',
            icon: Icon(
              Icons.home_rounded,
              color: kHintColor,
              size: 35,
            ),
            activeIcon: Icon(
              Icons.home_rounded,
              color: kMainColor,
              size: 35,
            ),
          ),
Run Code Online (Sandbox Code Playgroud)

并将以下内容添加到 BottomNavigationBar:

        selectedLabelStyle: TextStyle(fontSize: 0),
        unselectedLabelStyle: TextStyle(fontSize: 0),
Run Code Online (Sandbox Code Playgroud)


mil*_*kas 5

希望该代码段对某人有所帮助。对我来说效果很好。

bottomNavigationBar : new BottomNavigationBar(
      items: [
      BottomNavigationBarItem(
        icon: Icons.search,
        title: Padding(padding: EdgeInsets.all(0))
      ),
      BottomNavigationBarItem(
        icon: Icons.share,
        title: Padding(padding: EdgeInsets.all(0))
      ),
      BottomNavigationBarItem(
        icon: Icons.call,
        title: Padding(padding: EdgeInsets.all(0))
      )],
     type: BottomNavigationBarType.fixed
) 
//bottomNavBar
Run Code Online (Sandbox Code Playgroud)