Flutter中的底部导航栏样式

用户名

我有两个问题,

第一个问题:为什么当我尝试backgroundColor: Colors.transparent在底部导航栏中使用时,我的栏看起来像这样?

在此处输入图片说明

我的代码:

  @override
  Widget build(BuildContext context){
    return MaterialApp(
      home: Scaffold(
        body: _pageOptions[_selectedPage],
        bottomNavigationBar: new Theme(
          data: Theme.of(context).copyWith(
            // canvasColor: Colors.transparent

          ),
        child: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          selectedFontSize: 18,
          unselectedFontSize: 12,
          currentIndex: _selectedPage,
          showSelectedLabels: true,
          onTap: (int index){
            setState(() {
              _selectedPage = index;
            });
          },
          items: [
            BottomNavigationBarItem(
              icon:Padding(
                padding: EdgeInsets.only(left:10.0, right: 10.0)),
                title: Text('MAPS', style: TextStyle(letterSpacing: 2.0, fontWeight: FontWeight.bold)),

            ),
            BottomNavigationBarItem(
              icon:Padding(
                padding: EdgeInsets.only(left:10.0, right: 10.0)),
              title: Text('HOME', style: TextStyle(letterSpacing: 2.0, fontWeight: FontWeight.bold))
            ),
            BottomNavigationBarItem(
              icon:Padding(
                padding: EdgeInsets.only(left:10.0, right: 10.0)),
              title: Text('PROFILE', style: TextStyle(letterSpacing: 2.0, fontWeight: FontWeight.bold))
            ),
          ]
        ),
        )
      )
    );
  } 

第二个问题:如何在导航栏中在我的项目上方添加轮廓,以及如何更改其宽度(例如,当您选择时maps,轮廓应具有例如15px和另外两个5px等)。

像这样的人: 在此处输入图片说明

感谢您的任何答案:)

宙斯

之所以会出现阴影,是因为BottomNavBar的默认高程为8.0,将其更改为0.0

      bottomNavigationBar: BottomNavigationBar(
        elevation: 0.0,
        backgroundColor: Colors.transparent,
        items: [
          BottomNavigationBarItem(
            icon: Padding(padding: EdgeInsets.only(left: 10.0, right: 10.0)),
            title: Text(
              'MAPS',
              style: TextStyle(
                letterSpacing: 2.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: Padding(padding: EdgeInsets.only(left: 10.0, right: 10.0)),
            title: Text(
              'HOME',
              style: TextStyle(letterSpacing: 2.0, fontWeight: FontWeight.bold),
            ),
          ),
          BottomNavigationBarItem(
            icon: Padding(padding: EdgeInsets.only(left: 10.0, right: 10.0)),
            title: Text(
              'PROFILE',
              style: TextStyle(letterSpacing: 2.0, fontWeight: FontWeight.bold),
            ),
          ),
        ],
      ),

输出:

在此处输入图片说明

更新:脚手架颜色变化

class New extends StatefulWidget {
  @override
  _NewState createState() => _NewState();
}

class _NewState extends State<New> {

  List<Color> scaffoldColors = [Colors.white, Colors.green, Colors.blue];
  List<Widget> bodies = [
    Container(
      child: Center(
        child: Text("MAP", style: TextStyle(color: Colors.black),),
      ),
    ),
    Container(
      child: Center(
        child: Text("HOME", style: TextStyle(color: Colors.black),),
      ),
    ),
    Container(
      child: Center(
        child: Text("PROFILE", style: TextStyle(color: Colors.black),),
      ),
    ),
  ];
  var index = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: scaffoldColors[index],
      body: bodies[index],
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.transparent,
        elevation: 0.0,
        items: [
          BottomNavigationBarItem(
            icon: Padding(padding: EdgeInsets.only(left: 10.0, right: 10.0)),
            title: Text(
              'MAPS',
              style: TextStyle(
                letterSpacing: 2.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
          BottomNavigationBarItem(
            icon: Padding(padding: EdgeInsets.only(left: 10.0, right: 10.0)),
            title: Text(
              'HOME',
              style: TextStyle(letterSpacing: 2.0, fontWeight: FontWeight.bold),
            ),
          ),
          BottomNavigationBarItem(
            icon: Padding(padding: EdgeInsets.only(left: 10.0, right: 10.0)),
            title: Text(
              'PROFILE',
              style: TextStyle(letterSpacing: 2.0, fontWeight: FontWeight.bold),
            ),
          ),
        ],
        currentIndex: index,
        onTap: (index){
          setState(() {
            this.index = index;
          });
        },
      ),
    );
  }
}

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何根据Flutter中的条件更改底部导航栏项目

来自分类Dev

颤振底部导航栏样式问题

来自分类Dev

双击底部导航栏项目Flutter

来自分类Dev

抽屉中底部导航栏的抽屉

来自分类Dev

底部导航栏与Android中的ListView重叠

来自分类Dev

如何在Flutter中制作自定义底部导航栏

来自分类Dev

如何在Flutter中拆分底部导航栏项目的边距?

来自分类Dev

Flutter Quick Actions更改选定的底部导航栏项目

来自分类Dev

带有页面视图的Flutter底部导航栏

来自分类Dev

Flutter:将图标对准中间-底部导航栏

来自分类Dev

导航栏显示在底部

来自分类Dev

底部导航栏空白

来自分类Dev

创建底部导航栏

来自分类Dev

Bootstrap中样式折叠的导航栏

来自分类Dev

Swift中的YouTube样式导航栏

来自分类Dev

导航栏中的样式品牌和文本

来自分类Dev

按Flutter底部导航栏时,将显示Android底部导航

来自分类Dev

导航栏样式

来自分类Dev

Bootstrap-导航栏中的底部对齐菜单

来自分类Dev

如何从引导导航栏中删除边界底部

来自分类Dev

抖动中的底部导航栏颜色恢复为黑色

来自分类Dev

浮动操作按钮隐藏在底部导航栏中

来自分类Dev

当约束布局在ScrollView中时,如何修复底部导航栏?

来自分类Dev

如何在底部导航栏中添加一行

来自分类Dev

如何在Twitter Bootstrap中删除导航栏底部填充

来自分类Dev

控制颤动底部导航栏中的大尺寸点击文本

来自分类Dev

Flutter-使用底部导航栏图标进行多页导航

来自分类Dev

Flutter中的可滚动导航栏

来自分类Dev

导航抽屉和底部栏