2

有人可以帮我解决这个问题。我目前找到的唯一解决方案是将 showSelectedLabels 和 showUnselecedLabels 都设置为 false。但是,这将删除所有标签,但我只想删除添加按钮的标签。如果我只是使用占位符“”作为标签,我的添加按钮会偏离水平中心...

按钮关闭水平居中

我想要的结果

Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: tabs[_selectedIndex],
      ),
      bottomNavigationBar: BottomNavigationBar(
        elevation: 10,
        backgroundColor: Colors.white,
        type: BottomNavigationBarType.fixed,
        selectedIconTheme: IconThemeData(color: kPrimaryMagentaColor),
        selectedLabelStyle: TextStyle(fontWeight: FontWeight.w500),
        selectedItemColor: Colors.black,
        showSelectedLabels: true,
        showUnselectedLabels: true,
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Container(
              padding: kBottomNavIconLabelSpace,
              child: Icon(
                FeatherIcons.map,
                size: 26.5,
              ),
            ),
            label: 'Map',
          ),
          BottomNavigationBarItem(
            icon: Container(
              padding: kBottomNavIconLabelSpace,
              child: Icon(
                FeatherIcons.compass,
                size: 28,
              ),
            ),
            label: 'Discover',
          ),
          BottomNavigationBarItem(
            icon: Container(
              decoration: BoxDecoration(
                color: kPrimaryMagentaColor,
                shape: BoxShape.circle,
              ),
              padding: EdgeInsets.all(10),
              child: Icon(
                FeatherIcons.plus,
                color: Colors.white,
              ),
            ),
            label: "",
          ),
          BottomNavigationBarItem(
            icon: Container(
              padding: kBottomNavIconLabelSpace,
              child: Transform(
                alignment: Alignment.center,
                transform: Matrix4.rotationY(math.pi),
                child: Icon(
                  FeatherIcons.messageSquare,
                  size: 28,
                ),
              ),
            ),
            label: 'Inbox',
          ),
          BottomNavigationBarItem(
            icon: Container(
              padding: kBottomNavIconLabelSpace,
              child: Icon(
                FeatherIcons.calendar,
                size: 28,
              ),
            ),
            label: 'My Activity',
          ),
        ],
        currentIndex: _selectedIndex,
        onTap: _onItemTapped,
      ),
    );
4

3 回答 3

9

Add this to the BottomNavigationBar properties

showSelectedLabels: false,
showUnselectedLabels: false,
于 2021-07-31T18:00:18.423 回答
0

好的,所以这可以通过操纵Text's来实现fontSize

首先,更改label您为每个BottomNavigationBarItemto usetitle参数使用的所有 s。像这样,

Change label: 'Map' to title: Text('Map'). Similarly change it with all your BottomNavigationBarItem. Since this is not possible using label parameter.

Now, for your center BottomNavigationBarItem use it like this,

BottomNavigationBarItem(
  icon: Align(
    alignment: Alignment.bottomCenter,
    child: Container(
      decoration: BoxDecoration(color: Colors.deepPurple, shape: BoxShape.circle),
      padding: EdgeInsets.all(14),
      child: Icon(Icons.add, color: Colors.white),
    ),
  ),
  title: Text("", style: TextStyle(fontSize: 0)),
),

So, you are changing two things.

  1. Increase padding of your Container to EdgeInsets.all(14) to make the button look bigger.
  2. Change fontSize using style: TextStyle(fontSize: 0), this make the view invisible.

Now, you have something like this, change the color to whatever you want.

enter image description here

于 2021-05-18T16:26:51.553 回答
0

If you use 2 params with

showSelectedLabels: false, showUnselectedLabels: false,

with label != ""

You can get this issue.

于 2021-09-22T13:56:01.417 回答