Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振2底部导航栏不显示第二项的标签_Flutter - Fatal编程技术网

Flutter 颤振2底部导航栏不显示第二项的标签

Flutter 颤振2底部导航栏不显示第二项的标签,flutter,Flutter,嗨,我是新来的颤振2,有一个关于底部导航栏的问题。下面是我正在测试的代码 class BottomNavigationComponent extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return BottomNavigationBar( items: const <BottomNavigationBa

嗨,我是新来的颤振2,有一个关于底部导航栏的问题。下面是我正在测试的代码

class BottomNavigationComponent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: 'AL',
              backgroundColor: Colors.red),
          BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: 'BL',
              backgroundColor: Colors.green),
          BottomNavigationBarItem(
              icon: Icon(Icons.ac_unit_rounded),
              label: 'CL',
              backgroundColor: Colors.yellow),
          BottomNavigationBarItem(
              icon: Icon(Icons.access_alarm_sharp),
              label: 'DL',
              backgroundColor: Colors.orange),
    ]);
  }
}
class BottomNavigationComponent扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
//TODO:实现构建
返回底部导航栏(
项目:常数[
底部导航气压计(
图标:图标(Icons.home),
标签:“AL”,
背景颜色:颜色。红色),
底部导航气压计(
图标:图标(Icons.home),
标签:“BL”,
背景颜色:颜色。绿色),
底部导航气压计(
图标:图标(图标。ac_单位_四舍五入),
标签:“CL”,
背景颜色:颜色。黄色),
底部导航气压计(
图标:图标(图标。访问\u报警\u尖锐),
标签:“DL”,
背景颜色:颜色。橙色),
]);
}
}
我看到下面的屏幕

如果我删除任何一个BottomNavigationBarItem,那么该条将成为以下内容。您可以看到不再设置背景色

有人能帮忙吗?多谢各位

更新:

根据@Ali Mahdiyar的建议,我得到以下屏幕。它越来越好,并显示标签。但是,背景色似乎不起作用

试试这个

更新/////

class BottomNavigationComponent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return BottomNavigationBar(
type: BottomNavigationBarType.fixed,////////////this added

unselectedItemColor: Colors.black54,///////you can add this to set the items colors 
            items: const <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                  icon: Icon(Icons.home),
                  label: 'AL',
                  backgroundColor: Colors.red),
              BottomNavigationBarItem(
                  icon: Icon(Icons.home),
                  label: 'BL',
                  backgroundColor: Colors.green),
              BottomNavigationBarItem(
                  icon: Icon(Icons.ac_unit_rounded),
                  label: 'CL',
                  backgroundColor: Colors.yellow),
              BottomNavigationBarItem(
                  icon: Icon(Icons.access_alarm_sharp),
                  label: 'DL',
                  backgroundColor: Colors.orange),
        ]);
      }
    }

嗨@Ali Mahdiyar,谢谢你的建议。我试过了,标签显示出来了。但是,背景色似乎不起作用。我试着为每个项目设置不同的背景色,但现在都是白色的。你能用一个图像来解析背景色吗?你的意思是,我可以用一个图像来代替背景色吗?嗯……听起来不错,但有点奇怪。不,不,不,不,在这里发布你的应用程序的图片。哦,对不起,我错过了,明白了。请参阅我文章末尾的更新部分
BottomNavigationBarItem(
                  icon: Icon(Icons.access_alarm_sharp,color:Colors.black),
                  label: 'DL',
                  backgroundColor: Colors.orange),