将边框半径应用于 BottomNavigationBar

发布于 2025-01-15 10:07:19 字数 1741 浏览 3 评论 0原文

我需要将边框半径应用于 BottomNavigationBar 宽度。找到一个有效的解决方案很棘手 - 我需要稍后对栏应用更多样式,并且还需要一个与之兼容的解决方案(主要是:浮动操作按钮和阴影)。关于如何做有什么建议吗?

代码和屏幕:

看我有:

在此处输入图像描述

看看我需要:

在此处输入图像描述

代码:(在我的选项卡屏幕的支架中):

bottomNavigationBar: BottomNavigationBar(
    onTap: _selectPage,
    showSelectedLabels: false,
    showUnselectedLabels: false,
    currentIndex: _selectedPageIndex,
    type: BottomNavigationBarType.fixed,
    items: [
      //home
      BottomNavigationBarItem(
        icon: Icon(Icons.home, color: _customColorScheme['Icon 1']),
        activeIcon: Icon(Icons.home, color: _customColorScheme['Icon 2']),
        label: '',
      ),
      //favorite
      BottomNavigationBarItem(
        icon: Icon(Icons.favorite, color: _customColorScheme['Icon 1']),
        activeIcon:
            Icon(Icons.favorite, color: _customColorScheme['Icon 2']),
        label: '',
      ),
      //loockback
      BottomNavigationBarItem(
        icon: Icon(Icons.bar_chart, color: _customColorScheme['Icon 1']),
        activeIcon:
            Icon(Icons.bar_chart, color: _customColorScheme['Icon 2']),
        label: '',
      ),
      //info & support
      BottomNavigationBarItem(
        icon: Icon(Icons.info, color: _customColorScheme['Icon 1']),
        activeIcon: Icon(Icons.info, color: _customColorScheme['Icon 2']),
        label: '',
      ),
    ],
  ),

I need to apply a border radius to my BottomNavigationBar widet. It's tricky to find a solution that works - and I need to apply more stylings to the bar later on and need a solution that is compatible with that as well (mainly: Floating action button and a shadow). Any recommendation on how to do it?

Code and screens:

Look I have:

enter image description here

Look I need:

enter image description here

Code: (in the Scaffold of my tabs screen):

bottomNavigationBar: BottomNavigationBar(
    onTap: _selectPage,
    showSelectedLabels: false,
    showUnselectedLabels: false,
    currentIndex: _selectedPageIndex,
    type: BottomNavigationBarType.fixed,
    items: [
      //home
      BottomNavigationBarItem(
        icon: Icon(Icons.home, color: _customColorScheme['Icon 1']),
        activeIcon: Icon(Icons.home, color: _customColorScheme['Icon 2']),
        label: '',
      ),
      //favorite
      BottomNavigationBarItem(
        icon: Icon(Icons.favorite, color: _customColorScheme['Icon 1']),
        activeIcon:
            Icon(Icons.favorite, color: _customColorScheme['Icon 2']),
        label: '',
      ),
      //loockback
      BottomNavigationBarItem(
        icon: Icon(Icons.bar_chart, color: _customColorScheme['Icon 1']),
        activeIcon:
            Icon(Icons.bar_chart, color: _customColorScheme['Icon 2']),
        label: '',
      ),
      //info & support
      BottomNavigationBarItem(
        icon: Icon(Icons.info, color: _customColorScheme['Icon 1']),
        activeIcon: Icon(Icons.info, color: _customColorScheme['Icon 2']),
        label: '',
      ),
    ],
  ),

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃素的狼 2025-01-22 10:07:19

你可以试试这个:

bottomNavigationBar: Container(                                             
  decoration: BoxDecoration(                                                   
    borderRadius: BorderRadius.only(                                           
      topRight: Radius.circular(30), topLeft: Radius.circular(30)),            
    boxShadow: [                                                               
      BoxShadow(color: Colors.black38, spreadRadius: 0, blurRadius: 10),       
    ],                                                                         
  ),                                                                           
  child: ClipRRect(                                                            
    borderRadius: BorderRadius.only(                                           
    topLeft: Radius.circular(30.0),                                            
    topRight: Radius.circular(30.0),                                           
    ),                                                                         
    child: BottomNavigationBar(                                                
      items: <BottomNavigationBarItem>[                                        
        BottomNavigationBarItem(                                               
          icon: Icon(Icons.favorite), title: Text('Favourite')),               
        BottomNavigationBarItem(                                               
          icon: Icon(Icons.favorite), title: Text('Favourite'))                
      ],                                                                       
    ),                                                                         
  )                                                                            
)

You can try this:

bottomNavigationBar: Container(                                             
  decoration: BoxDecoration(                                                   
    borderRadius: BorderRadius.only(                                           
      topRight: Radius.circular(30), topLeft: Radius.circular(30)),            
    boxShadow: [                                                               
      BoxShadow(color: Colors.black38, spreadRadius: 0, blurRadius: 10),       
    ],                                                                         
  ),                                                                           
  child: ClipRRect(                                                            
    borderRadius: BorderRadius.only(                                           
    topLeft: Radius.circular(30.0),                                            
    topRight: Radius.circular(30.0),                                           
    ),                                                                         
    child: BottomNavigationBar(                                                
      items: <BottomNavigationBarItem>[                                        
        BottomNavigationBarItem(                                               
          icon: Icon(Icons.favorite), title: Text('Favourite')),               
        BottomNavigationBarItem(                                               
          icon: Icon(Icons.favorite), title: Text('Favourite'))                
      ],                                                                       
    ),                                                                         
  )                                                                            
)
萤火眠眠 2025-01-22 10:07:19

您可以使用一个包 animated_bottom_navigation_bar: ^0.3.2 它们有不同数量的导航栏,并且有一个您需要的圆角导航栏。我希望这能满足您的需求。

You can use a package animated_bottom_navigation_bar: ^0.3.2 they have various amount of navigation bars and have a rounded corner one that you need. I hope this will fulfill what you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文