【问题标题】:How do I clip the edges of my tab bar container in flutter?如何在颤动中剪辑标签栏容器的边缘?
【发布时间】:2020-01-03 13:58:35
【问题描述】:

我的屏幕底部有一个容器,它有一个 BottomNavigationBar。我希望容器获得我的背景颜色。即使在添加 CLipRRect 之后,它也没有得到纠正。我还尝试使容器透明,但它显示了一个错误,我无法为容器分配颜色并给它一个 boxDecoration。我希望多余的白色部分合并到我的背景中。

//已编辑

如何去除背景中的阴影?

Widget _bottomNavigationBar(int selectedIndex) => ClipRect(
    child: Container(
        height: 80,
        decoration: BoxDecoration(
          borderRadius: const BorderRadius.all(Radius.circular(52.0)),
          boxShadow: <BoxShadow>[
            BoxShadow(
                color: Colors.grey.withOpacity(0.3),
                offset: const Offset(0.0, 0.0),
                blurRadius: 52.0),
          ],
        ),
        child: ClipRRect(
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(52.0),
              topRight: Radius.circular(52.0)),
          child: BottomNavigationBar(
            selectedItemColor: Color(0xFFFE524B),
            unselectedItemColor: Color(0xFFFF8C3B),
            onTap: (int index) => setState(() => _selectedIndex = index),
            currentIndex: selectedIndex,
            items: const <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                  icon: Icon(
                    Entypo.home,
                    size: 30,
                  ),
                  title: Text('')),
              BottomNavigationBarItem(
                  icon: Icon(
                    Entypo.game_controller,
                    size: 30,
                  ),
                  title: Text('[![enter image description here][1]][1]')),
              BottomNavigationBarItem(
                  icon: Icon(
                    Entypo.wallet,
                    size: 30,
                  ),
                  title: Text('')),
            ],
          ),
        )),
  );

【问题讨论】:

  • 你可以把color属性放在BoxDecoration里面。它将修复您收到的错误,但我不确定它会实现您想要的。可以试试吗?
  • 不,我试过了,但它没有合并到我的背景中。

标签: user-interface flutter dart user-experience tabbar


【解决方案1】:

这其实不是底部导航栏的问题。您需要将父 Scaffold 小部件的“extendBody”设置为“true”。这会将脚手架主体内容一直延伸到屏幕底部!

Scaffold(
  extendBody: true,
  bottomNavigationBar: _bottomNavigationBar(selectedIndex),
);

【讨论】:

  • 刚刚有另一个问题,我该如何解决出现的阴影? 问题已编辑
  • 如果您有单独的问题,我建议您打开一个新问题。这个已经解决了。
  • @SimranAswani 不客气!抱歉,我不确定您指的是哪个影子。如果您可以使用要删除的阴影的新屏幕截图打开另一个问题,也许最好。我也会留下来回答这个问题!
猜你喜欢
  • 2021-11-07
  • 2020-12-18
  • 1970-01-01
  • 2022-01-17
  • 2023-03-22
  • 1970-01-01
  • 2014-05-27
  • 1970-01-01
  • 2020-01-24
相关资源
最近更新 更多